[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: dwww: cat and file (pipe race condition)

On Thu, Mar 30, 2000 at 10:03:14AM -0500, Daniel Martin wrote:
> Well, if I do a 
> $process | file -b - | magic2mime
> where "$process" is anything that produces a large amount of output
> slowly, then the process is killed by a SIGPIPE in short order.
> If, however, I do:
> $process | (file -b -; cat >/dev/null) | magic2mime
> then it seems that the process runs happily (that is, no signals) to
> completion.
> However, this may not be what you really would want.  (Since waiting
> for process to finish could cause the webserver to time out)  What
> your problem may be is that somehow the cat process is not receiving
> the SIGPIPE signal; I would then try to see about rewriting the dwww
> script so that it does.  (I'm not sure how to do this, since the bash
> manpage seems to imply that one can't change which signals are ignored 
> by the shell).

I just read this one message so I don't know what the original
problem is.  However, I think you are misdiagnosing or misexplaining
this.  The SIGPIPE goes to and only to $process.  The reason is that
file closes its stdin as soon as it has ready a few bytes, with the
result that $process then has nowhere to write.  cat cannot get a
SIGPIPE because it is writing to /dev/null, which rarely stops
accepting bits.

As far as the web server timing out, without knowing the full
context I believe that whatever script is calling this pipeline can
just kill it after reading what it needs from magic2mime.  Course,
this might be a problem if any of the programs in the pipeline
handle their buffers in unfortunate ways, causing the output from
magic2mime to wait for the completion of $process....

My apologies if you understood this and I just misread your message.


Reply to: