[New-bugs-announce] [issue35426] test_signal.test_interprocess_signal() race condition
STINNER Victor
report at bugs.python.org
Thu Dec 6 07:36:00 EST 2018
New submission from STINNER Victor <vstinner at redhat.com>:
test_signal.test_interprocess_signal() has a race condition:
with self.subprocess_send_signal(pid, "SIGUSR1") as child: # here
self.wait_signal(child, 'SIGUSR1', SIGUSR1Exception)
The test only except SIGUSR1Exception inside wait_signal(), but the signal can be sent during subprocess_send_signal() call. assertRaises(SIGUSR1Exception) should surround these two lines instead. wait_signal() shouldn't handle the signal.
Or wait_signal() should call subprocess_send_signal().
It seems like Python 2.7 has the proper design. It might be a regression introduced by myself in:
commit 32eb840a42ec0e131daac48d43aa35290e72571e
Author: Victor Stinner <victor.stinner at gmail.com>
Date: Tue Mar 15 11:12:35 2016 +0100
Issue #26566: Rewrite test_signal.InterProcessSignalTests
* Add Lib/test/signalinterproctester.py
* Don't disable the garbage collector anymore
* Don't use os.fork() with a subprocess to not inherit existing signal handlers
or threads: start from a fresh process
* Don't use UNIX kill command to send a signal but Python os.kill()
* Use a timeout of 10 seconds to wait for the signal instead of 1 second
* Always use signal.pause(), instead of time.wait(1), to wait for a signal
* Use context manager on subprocess.Popen
* remove code to retry on EINTR: it's no more needed since the PEP 475
* remove unused function exit_subprocess()
* Cleanup the code
FAIL: test_interprocess_signal (test.test_signal.PosixTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/home/buildbot/python/3.7.koobs-freebsd10.nondebug/build/Lib/test/test_signal.py", line 62, in test_interprocess_signal
assert_python_ok(script)
File "/usr/home/buildbot/python/3.7.koobs-freebsd10.nondebug/build/Lib/test/support/script_helper.py", line 157, in assert_python_ok
return _assert_python(True, *args, **env_vars)
File "/usr/home/buildbot/python/3.7.koobs-freebsd10.nondebug/build/Lib/test/support/script_helper.py", line 143, in _assert_python
res.fail(cmd_line)
File "/usr/home/buildbot/python/3.7.koobs-freebsd10.nondebug/build/Lib/test/support/script_helper.py", line 84, in fail
err))
AssertionError: Process return code is 1
command line: ['/usr/home/buildbot/python/3.7.koobs-freebsd10.nondebug/build/python', '-X', 'faulthandler', '-I', '/usr/home/buildbot/python/3.7.koobs-freebsd10.nondebug/build/Lib/test/signalinterproctester.py']
stdout:
---
---
stderr:
---
E/usr/home/buildbot/python/3.7.koobs-freebsd10.nondebug/build/Lib/subprocess.py:858: ResourceWarning: subprocess 64567 is still running
ResourceWarning, source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
======================================================================
ERROR: test_interprocess_signal (__main__.InterProcessSignalTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/home/buildbot/python/3.7.koobs-freebsd10.nondebug/build/Lib/test/signalinterproctester.py", line 68, in test_interprocess_signal
with self.subprocess_send_signal(pid, "SIGUSR1") as child:
File "/usr/home/buildbot/python/3.7.koobs-freebsd10.nondebug/build/Lib/test/signalinterproctester.py", line 50, in subprocess_send_signal
return subprocess.Popen(args)
File "/usr/home/buildbot/python/3.7.koobs-freebsd10.nondebug/build/Lib/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/usr/home/buildbot/python/3.7.koobs-freebsd10.nondebug/build/Lib/subprocess.py", line 1476, in _execute_child
part = os.read(errpipe_read, 50000)
File "/usr/home/buildbot/python/3.7.koobs-freebsd10.nondebug/build/Lib/test/signalinterproctester.py", line 22, in sigusr1_handler
raise SIGUSR1Exception
SIGUSR1Exception
----------------------------------------------------------------------
Ran 1 test in 0.223s
FAILED (errors=1)
---
----------------------------------------------------------------------
Ran 43 tests in 31.872s
FAILED (failures=1, skipped=2)
test test_signal failed
----------
components: Tests
messages: 331233
nosy: vstinner
priority: normal
severity: normal
status: open
title: test_signal.test_interprocess_signal() race condition
versions: Python 3.6, Python 3.7, Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35426>
_______________________________________
More information about the New-bugs-announce
mailing list