[issue12469] test_faulthandler failures on FreeBSD 6

Charles-François Natali report at bugs.python.org
Sat Jul 2 10:31:23 CEST 2011


Charles-François Natali <neologix at free.fr> added the comment:

>> On FreeBSD 6, os.kill(os.getpid(), signum) calls immediatly
>> the signal handler before the creation of the first thread (...),
>> whereas the signal handler is called "later" (when exactly?) after
>> the creation of the first thread (default after my commit).
>
> It looks like a kernel/libc bug. At least, it doesn't conform to POSIX.1-2001. Extract of the Linux manual page of the kill function (syscall):
>

Yes, that's definitely a kernel/libc bug, like  #12392.

> I see two options:
>
>  - revert my commit and fix #12392 (test_signal) differently
>  - skip test_register, test_register_file, test_register_threads and test_stack_overflow can on freebsd6
>
> I prefer to revert my commit because it introduced an unexpected behaviour on signal handling. It calls the signal handler later when the process sends a signal to itself, even if the application don't use threads.
>

I'm also in favor of reverting this commit.

> The new fix for #12392 is to ensure that at least one thread was created. We can for example use the following code at the beginning of test_signal:
>
> if sys.platform in ('freebsd5', 'freebsd6'):
>  # On FreeBSD6, pthread_kill() doesn't work on the main thread
>  # before the creation of the first thread
>  import threading
>  t = threading.Thread(target=lambda: None)
>  t.start()
>  t.join()
>
> Then test_signal.test_pthread_kill_main_thread() should be skipped or patched for freebsd6.
>

Yes.

By the way, this also explains the test.test_signal.WakeupSignalTests
failures we had on FreeBSD 6.4.
Here's what I wrote in see http://bugs.python.org/issue8407#msg137382 :

"""
"""
======================================================================
FAIL: test_signum (test.test_signal.WakeupSignalTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/home/db3l/buildarea/3.x.bolen-freebsd/build/Lib/test/test_signal.py",
line 272, in test_signum
    self.check_signum(signal.SIGUSR1, signal.SIGALRM)
  File "/usr/home/db3l/buildarea/3.x.bolen-freebsd/build/Lib/test/test_signal.py",
line 238, in check_signum
    self.assertEqual(raised, signals)
AssertionError: Tuples differ: (14, 30) != (30, 14)

First differing element 0:
14
30

- (14, 30)
+ (30, 14)
"""

This means that the signals are not delivered in order.
Normally, pending signals are checked upon return to user-space, so
trip_signal should be called when the kill syscall returns, so signal
numbers should be written in order to the wakeup FD (and here it looks
like the lowest-numbered signal is delivered first).
You could try adding a short sleep before the second kill (or just
pass unordered=True to check_signum, but in that case we don't check
the correct ordering).
"""

Since signals are not delivered synchronously when the kill() syscall
returns, they are delivered later, and the order is not preserved.

The patch above (creating a dummy thread at the beginning of
test_signal) should fix this, so you might be able to revert
http://hg.python.org/cpython/rev/29e08a98281d .

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12469>
_______________________________________


More information about the Python-bugs-list mailing list