Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: coproc fd leak leading to possible deadlock



On Mar 6, 10:53pm, Stephane Chazelas wrote:
: Subject: coproc fd leak leading to possible deadlock
:
: When we run an external command as a coproc, all is fine, but if
: we run a subshell, that subshell ends up having open fds for
: both ends of both pipes, leading to potential deadlocks

Yes, I've been pointing out problems with coproc descriptor handling
for a while now (search zsh-worker mailing list archives).  So far I
have not found any issues with zsh's descriptor handling that are not
also shared by at least bash if not also ksh, so there hasn't been any
effort put into fixing things for a while.

: ~$ exec zsh -f
: sc% coproc {sleep 100; sleep 100}

The workaround for this one is to run a dummy coprocess *inside* the
coprocess:

% coproc { coproc : ; sleep 100; sleep 100 }

This should force closed the descriptors in the subshell that were
inherited from the parent shell, leaving the stdin/stdout connected to
the original pipes.

There's some discussion of why this happens (and why it's convoluted
to detect the situation) in the archives.  The short answer is that the
descriptors are close-on-exec [which is why "coproc sh ..." works] but
there's no exec with a subshell.



Messages sorted by: Reverse Date, Date, Thread, Author