Bug 695656 - possible race condition when using trap, signal is lost
possible race condition when using trap, signal is lost
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: bash (Show other bugs)
6.1
Unspecified Unspecified
low Severity low
: rc
: ---
Assigned To: Roman Rakus
Martin Kyral
:
Depends On:
Blocks: 1025764
  Show dependency treegraph
 
Reported: 2011-04-12 06:40 EDT by Jan Stancek
Modified: 2014-01-12 19:13 EST (History)
4 users (show)

See Also:
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 03:07:24 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Jan Stancek 2011-04-12 06:40:31 EDT
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 08:08:52 EDT
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-12 22:53:21 EDT
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 Product and Program Management 2011-04-13 02:00:26 EDT
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 02:19:29 EDT
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 01:55:34 EDT
(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 08:42:21 EDT
The possible solution is to block the signal while the trap string and handler are
being modified.
Comment 8 RHEL Product and Program Management 2011-07-05 19:41:14 EDT
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 Yeghiayan 2012-02-14 18:08:26 EST
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 07:00:13 EDT
Fixed in bash-4.1.2-12.el6
Comment 17 errata-xmlrpc 2013-02-21 03:07:24 EST
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

Note You need to log in before you can comment on or make changes to this bug.