* Hang opening a pipe written to by a child, with SIGCHLD
@ 2012-04-02 14:46 Lluís Batlle i Rossell
2012-04-02 14:49 ` Shea Levy
0 siblings, 1 reply; 6+ messages in thread
From: Lluís Batlle i Rossell @ 2012-04-02 14:46 UTC (permalink / raw)
To: linux-kernel
Hello,
I had troubles running a simple bash script where a child wrote to a named pipe
before dying, and the parent opened and read the pipe.
On a computer, my script hangs always. Also under 'strace'. Not under 'strace
-f'. Thinking of some race, I wrote a small script that hangs in the linuxes I
could try (3.2.11 now):
----------
#!/var/run/current-system/sw/bin/bash
PIPE=/tmp/pipe
rm -f $PIPE
mkfifo $PIPE
function spawn {
echo DONE > $PIPE
}
spawn sleep 1 &
while true; do
echo reading
while read LINE < $PIPE; do
echo $LINE
spawn &
done
done
-------------
bash uses SA_RESTART on SIGCHLD handler, and nevertheless the script halts at
printing some amount of 'DONE'. Strace shows it's inside the open() call, while the open
call has been interrupted by SIGCHLD. One of the computers I have hangs at the *first* DONE always, and that's why it's annoying to me.
Can anyone reproduce this?
Regards,
Lluís.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Hang opening a pipe written to by a child, with SIGCHLD
2012-04-02 14:46 Hang opening a pipe written to by a child, with SIGCHLD Lluís Batlle i Rossell
@ 2012-04-02 14:49 ` Shea Levy
2012-04-02 18:50 ` Lluís Batlle i Rossell
0 siblings, 1 reply; 6+ messages in thread
From: Shea Levy @ 2012-04-02 14:49 UTC (permalink / raw)
To: Lluís Batlle i Rossell; +Cc: linux-kernel
On 04/02/2012 10:46 AM, Lluís Batlle i Rossell wrote:
> Hello,
>
> I had troubles running a simple bash script where a child wrote to a named pipe
> before dying, and the parent opened and read the pipe.
>
> On a computer, my script hangs always. Also under 'strace'. Not under 'strace
> -f'. Thinking of some race, I wrote a small script that hangs in the linuxes I
> could try (3.2.11 now):
>
> ----------
> #!/var/run/current-system/sw/bin/bash
>
> PIPE=/tmp/pipe
>
> rm -f $PIPE
> mkfifo $PIPE
>
> function spawn {
> echo DONE> $PIPE
> }
>
> spawn sleep 1&
>
> while true; do
> echo reading
> while read LINE< $PIPE; do
> echo $LINE
> spawn&
> done
> done
> -------------
>
> bash uses SA_RESTART on SIGCHLD handler, and nevertheless the script halts at
> printing some amount of 'DONE'. Strace shows it's inside the open() call, while the open
> call has been interrupted by SIGCHLD. One of the computers I have hangs at the *first* DONE always, and that's why it's annoying to me.
>
> Can anyone reproduce this?
I've reproduced this on my system as well (3.3). No idea about cause though.
~Shea
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Hang opening a pipe written to by a child, with SIGCHLD
2012-04-02 14:49 ` Shea Levy
@ 2012-04-02 18:50 ` Lluís Batlle i Rossell
2012-04-02 20:20 ` Lluís Batlle i Rossell
0 siblings, 1 reply; 6+ messages in thread
From: Lluís Batlle i Rossell @ 2012-04-02 18:50 UTC (permalink / raw)
To: Shea Levy; +Cc: linux-kernel
On Mon, Apr 02, 2012 at 10:49:10AM -0400, Shea Levy wrote:
> On 04/02/2012 10:46 AM, Lluís Batlle i Rossell wrote:
> >Can anyone reproduce this?
>
> I've reproduced this on my system as well (3.3). No idea about cause though.
>
Thank you Shea,
with a little change, adding "sleep 0.1" makes it hang early in all (few)
linuces I tried: Let me know if this helps you reproduce the problem.
As before, hangs under strace, does not hang under 'strace -f'. Sorry if I'm
misunderstanding something.
New script:
----------
#!/bin/sh
PIPE=/tmp/pipe
rm -f $PIPE
mkfifo $PIPE
set -x
spawn() {
sleep 0.1
echo DONE > $PIPE
}
spawn &
while true; do
while read LINE < $PIPE; do
echo $LINE
spawn &
done
done
-----------
Regards,
Lluís.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Hang opening a pipe written to by a child, with SIGCHLD
2012-04-02 18:50 ` Lluís Batlle i Rossell
@ 2012-04-02 20:20 ` Lluís Batlle i Rossell
0 siblings, 0 replies; 6+ messages in thread
From: Lluís Batlle i Rossell @ 2012-04-02 20:20 UTC (permalink / raw)
To: Shea Levy; +Cc: linux-kernel
On Mon, Apr 02, 2012 at 08:50:57PM +0200, Lluís Batlle i Rossell wrote:
> On Mon, Apr 02, 2012 at 10:49:10AM -0400, Shea Levy wrote:
> > On 04/02/2012 10:46 AM, Lluís Batlle i Rossell wrote:
> > >Can anyone reproduce this?
> >
> > I've reproduced this on my system as well (3.3). No idea about cause though.
> >
>
> Thank you Shea,
All clear. I had a race condition; sorry for the noise. Proper synchronization
through close() in the child and read() = 0 in the parent fixes all.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Hang opening a pipe written to by a child, with SIGCHLD
[not found] <20120409120326.f0ce7a94.akpm@linux-foundation.org>
@ 2012-04-10 22:55 ` Oleg Nesterov
2012-04-10 23:12 ` Oleg Nesterov
0 siblings, 1 reply; 6+ messages in thread
From: Oleg Nesterov @ 2012-04-10 22:55 UTC (permalink / raw)
To: Andrew Morton, Lluís Batlle i Rossell; +Cc: linux-kernel
On 04/09, Andrew Morton wrote:
>
> Begin forwarded message:
>
> Date: Mon, 2 Apr 2012 16:46:11 +0200
> From: Lluís Batlle i Rossell <viric@viric.name>
> To: linux-kernel@vger.kernel.org
> Subject: Hang opening a pipe written to by a child, with SIGCHLD
>
>
> Hello,
>
> I had troubles running a simple bash script where a child wrote to a named pipe
> before dying, and the parent opened and read the pipe.
>
> On a computer, my script hangs always. Also under 'strace'. Not under 'strace
> -f'. Thinking of some race, I wrote a small script that hangs in the linuxes I
> could try (3.2.11 now):
>
> ----------
> #!/var/run/current-system/sw/bin/bash
>
> PIPE=/tmp/pipe
>
> rm -f $PIPE
> mkfifo $PIPE
>
> function spawn {
> echo DONE > $PIPE
> }
>
> spawn sleep 1 &
>
> while true; do
> echo reading
> while read LINE < $PIPE; do
> echo $LINE
> spawn &
> done
> done
Looks like, it hangs "correctly". At least from the kernel pov.
The parent sleeps in fifo_open()->wait_for_partner(), but there
are no pipe->writers.
Note that the parent (bash) re-opens /tmp/pipe after every "spawn".
Now,
- the parent (bash) forks the new child
- the new child sleeps waiting for reader
- the parent does open(pipe), this wakes up the child
- the child opens the pipe, writes, and exits
- the open from the child wakes up the parent, but
since it exits quickly fifo_open(FMODE_READ) can
notice the pending SIGCHLD and return -EINTR
- the parent restarts sys_open(), but nobody can
open it for writing
May be you can ask bash developers. Perhaps bash can move the
"restore stdin" logic into the child process, I dunno.
Or may be you can "fix" this script, just add "exec < $PIPE"
before the main "while true" loop.
Oleg.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Hang opening a pipe written to by a child, with SIGCHLD
2012-04-10 22:55 ` Oleg Nesterov
@ 2012-04-10 23:12 ` Oleg Nesterov
0 siblings, 0 replies; 6+ messages in thread
From: Oleg Nesterov @ 2012-04-10 23:12 UTC (permalink / raw)
To: Andrew Morton, Lluís Batlle i Rossell; +Cc: linux-kernel
On 04/11, Oleg Nesterov wrote:
>
> Or may be you can "fix" this script, just add "exec < $PIPE"
> before the main "while true" loop.
Cough, no ;) this can equally race with the exiting child.
Oleg.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-04-10 23:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-02 14:46 Hang opening a pipe written to by a child, with SIGCHLD Lluís Batlle i Rossell
2012-04-02 14:49 ` Shea Levy
2012-04-02 18:50 ` Lluís Batlle i Rossell
2012-04-02 20:20 ` Lluís Batlle i Rossell
[not found] <20120409120326.f0ce7a94.akpm@linux-foundation.org>
2012-04-10 22:55 ` Oleg Nesterov
2012-04-10 23:12 ` Oleg Nesterov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).