Bug 695656

Summary: possible race condition when using trap, signal is lost
Product: Red Hat Enterprise Linux 6 Reporter: Jan Stancek <jstancek>
Component: bashAssignee: Roman Rakus <rrakus>
Status: CLOSED ERRATA QA Contact: Martin Kyral <mkyral>
Severity: low Docs Contact:
Priority: low    
Version: 6.1CC: lizf, mkyral, prc, tsmetana
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: bash-4.1.2-12.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1025764 (view as bug list) Environment:
Last Closed: 2013-02-21 08:07:24 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1025764    

Description Jan Stancek 2011-04-12 10:40:31 UTC
Description of problem:
This issue came up while running ltp cgroups regression tests.
Some of stress tests have very short loops and often call 'trap'. The task is then signalled, but the signal is occasionally 'lost'.

If this is known issue/limitation, which can't be fixed, perhaps a note could be added to man pages.

Version-Release number of selected component (if applicable):
Red Hat Enterprise Linux Server release 6.1 Beta (Santiago)
bash-4.1.2-8.el6.x86_64

How reproducible:
100% within 15 seconds

Steps to Reproduce:
1. run this script:
--- cut ---
#!/bin/bash

cat > traploop.sh <<EOF
while true; do
    trap exit SIGUSR1;
done
EOF

chmod a+x traploop.sh

i=0
while true; do
    ./traploop.sh &
    sleep 1
    echo "Sending SIGUSR1 to $!"
    kill -SIGUSR1 $!
    wait $!
    echo "No. $i: OK"
    i=$((i+1))
done
--- cut ---

Actual results:
Reproducer script gets stuck after couple of seconds.

Expected results:
Reproducer script will produce output each second.

Additional info:
Also reproducible on RHEL6.0, bash-4.1.2-3.el6.x86_64
Obvious workaround is to move trap outside the loop.

Comment 2 Roman Rakus 2011-04-12 12:08:52 UTC
Thanks for the report. Looks like the bug in re-setting signal handler. I will investigate it deeper.
For some reason bash set signal to be ignored before it set it to be handled and you hit the situation when it is ignored.

Comment 3 Roman Rakus 2011-04-13 02:53:21 UTC
Answer from upstream: http://www.mail-archive.com/bug-bash@gnu.org/msg09078.html

So it won't be changed. And I think it's not good set up trap many times if you can set it once at start. Is there any reason to set up trap in every loop run?

Comment 4 RHEL Program Management 2011-04-13 06:00:26 UTC
Since RHEL 6.1 External Beta has begun, and this bug remains
unresolved, it has been rejected as it is not proposed as
exception or blocker.

Red Hat invites you to ask your support representative to
propose this request, if appropriate and relevant, in the
next release of Red Hat Enterprise Linux.

Comment 5 Jan Stancek 2011-04-13 06:19:29 UTC
As for the cgroups tests in question
(./testcases/kernel/controllers/cgroup/test_*.sh), I don't see any reason to
keep it in loop. I'll CC author of the test.

Theoretically, you might want to change trap to use different handlers. Say you
want to handle signals coming at odd seconds with different handler than
signals coming at even seconds. One way would be to modify trap by switching
between 2 handlers.

> So it won't be changed. And I think it's not good set up trap many times
Sounds like a remark which could be added to man page.

Comment 6 Roman Rakus 2011-04-14 05:55:34 UTC
(In reply to comment #5)
> As for the cgroups tests in question
> (./testcases/kernel/controllers/cgroup/test_*.sh), I don't see any reason to
> keep it in loop. I'll CC author of the test.
> 
> Theoretically, you might want to change trap to use different handlers. Say you
> want to handle signals coming at odd seconds with different handler than
> signals coming at even seconds. One way would be to modify trap by switching
> between 2 handlers.
Or one handler which will check the seconds?
> 
> > So it won't be changed. And I think it's not good set up trap many times
> Sounds like a remark which could be added to man page.

Yes. It could be documented.

Comment 7 Roman Rakus 2011-04-18 12:42:21 UTC
The possible solution is to block the signal while the trap string and handler are
being modified.

Comment 8 RHEL Program Management 2011-07-05 23:41:14 UTC
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated
in the current release, Red Hat is unfortunately unable to
address this request at this time. Red Hat invites you to
ask your support representative to propose this request, if
appropriate and relevant, in the next release of Red Hat
Enterprise Linux. If you would like it considered as an
exception in the current release, please ask your support
representative.

Comment 10 Suzanne Logcher 2012-02-14 23:08:26 UTC
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated
in the current release, Red Hat is unfortunately unable to
address this request at this time. Red Hat invites you to
ask your support representative to propose this request, if
appropriate and relevant, in the next release of Red Hat
Enterprise Linux. If you would like it considered as an
exception in the current release, please ask your support
representative.

Comment 13 Roman Rakus 2012-08-28 11:00:13 UTC
Fixed in bash-4.1.2-12.el6

Comment 17 errata-xmlrpc 2013-02-21 08:07:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2013-0306.html