Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple errors in test_socket on OpenBSD #57114

Closed
rpointel mannequin opened this issue Sep 5, 2011 · 18 comments
Closed

multiple errors in test_socket on OpenBSD #57114

rpointel mannequin opened this issue Sep 5, 2011 · 18 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@rpointel
Copy link
Mannequin

rpointel mannequin commented Sep 5, 2011

BPO 12905
Nosy @vstinner
Files
  • OpenBSD_test_socket_gdb.log: gdb output backtrace
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-02-28.08:20:31.170>
    created_at = <Date 2011-09-05.21:33:32.763>
    labels = ['type-bug', 'invalid']
    title = 'multiple errors in test_socket on OpenBSD'
    updated_at = <Date 2012-02-28.08:20:31.169>
    user = 'https://bugs.python.org/rpointel'

    bugs.python.org fields:

    activity = <Date 2012-02-28.08:20:31.169>
    actor = 'neologix'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-02-28.08:20:31.170>
    closer = 'neologix'
    components = []
    creation = <Date 2011-09-05.21:33:32.763>
    creator = 'rpointel'
    dependencies = []
    files = ['23105']
    hgrepos = []
    issue_num = 12905
    keywords = []
    message_count = 18.0
    messages = ['143564', '143565', '143572', '143578', '143586', '143640', '143642', '143648', '143650', '143651', '143652', '143653', '143699', '143744', '143755', '146611', '154535', '154537']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'neologix', 'rpointel']
    pr_nums = []
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue12905'
    versions = ['Python 3.2', 'Python 3.3']

    @rpointel
    Copy link
    Mannequin Author

    rpointel mannequin commented Sep 5, 2011

    Hi,

    I have few problems in test_socket.py.

    1. test_sendall_interrupted blocks on OpenBSD, I must Ctrl+c to interrupt the test. I added a skip to have full regress tests, but I think it's not the proper way.
      I have run it into gdb, and ctrl+c it:
      test_sendall_interrupted (main.GeneralModuleTests) ... [New process 20677]
      ^C
      Program received signal SIGINT, Interrupt.
      0x0000000206d2378a in poll () from /usr/lib/libc.so.60.1
      (gdb) bt
      #0 0x0000000206d2378a in poll () from /usr/lib/libc.so.60.1
      Support "bpo-" in Misc/NEWS #1 0x0000000205f4e4aa in _thread_kern_poll (wait_reqd=Variable "wait_reqd" is not available.
      )
      at /usr/src/lib/libpthread/uthread/uthread_kern.c:780
      Rename README to README.rst and enhance formatting #2 0x0000000205f4f3a8 in _thread_kern_sched (scp=0x0)
      at /usr/src/lib/libpthread/uthread/uthread_kern.c:382
      bpo-29403: Fix mock's broken autospec behavior on method-bound builtin functions #3 0x0000000205f43ade in sendto (fd=8, msg=0x2047bb040, len=1044480, flags=0, to=0x0, to_len=0)
      at /usr/src/lib/libpthread/uthread/uthread_sendto.c:63
      Update Python Software Foundation Copyright Year. #4 0x0000000210a5b243 in sock_sendall (s=0x20115c948, args=0x2011510d0)
      at /usr/ports/pobj/Python-3.2.2/Python-3.2.2/Modules/socketmodule.c:2699
      Convert READMEs to rst #5 0x0000000000468992 in PyEval_EvalFrameEx (f=0x20a281c30, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:3921
      Add Pycharm's .idea directory to gitignore #6 0x000000000046a95c in PyEval_EvalCodeEx (_co=0x20fc581b0, globals=Variable "globals" is not available.
      ) at Python/ceval.c:3350
      bpo-29527: Disable broken Travis docs job #7 0x0000000000466df6 in PyEval_EvalFrameEx (f=0x20a9a3c30, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4019
      Change some mercurial/ hg.python.org references. #8 0x0000000000468c1a in PyEval_EvalFrameEx (f=0x2033af030, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4009
      Fix some deprecation warnings in Doc/conf.py #9 0x000000000046a95c in PyEval_EvalCodeEx (_co=0x2028a9de8, globals=Variable "globals" is not available.
      ) at Python/ceval.c:3350
      bpo-29474: Improve documentation for weakref.WeakValueDictionary #10 0x0000000000466df6 in PyEval_EvalFrameEx (f=0x2052f1430, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4019
      bpo-29474: Improve documentation for weakref.WeakValueDictionary #11 0x000000000046a95c in PyEval_EvalCodeEx (_co=0x2028a9f58, globals=Variable "globals" is not available.
      ) at Python/ceval.c:3350
      bpo-29524: Add Objects/call.c file #12 0x0000000000511ce3 in function_call (func=0x2050d5620, arg=0x20115d330, kw=0x2052f0030)
      at Objects/funcobject.c:629
      Fix bpo-29528 Use a secure variable to stop spam #13 0x00000000004e4a7f in PyObject_Call (func=0x2050d5620, arg=0x20115d330, kw=0x2052f0030)
      at Objects/abstract.c:2149
      Disable Travis docs job until a fix is found #14 0x000000000046456d in PyEval_EvalFrameEx (f=0x2052f0e30, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4236
      Use Sphinx 1.4.9 for now #15 0x000000000046a95c in PyEval_EvalCodeEx (_co=0x2028ad268, globals=Variable "globals" is not available.
      ) at Python/ceval.c:3350
      Make Travis docs build more lenient #16 0x0000000000511ce3 in function_call (func=0x2050d5790, arg=0x20115d240, kw=0x0)
      at Objects/funcobject.c:629
      bpo-29438: fixed use-after-free in key sharing dict #17 0x00000000004e4a7f in PyObject_Call (func=0x2050d5790, arg=0x20115d240, kw=0x0)
      at Objects/abstract.c:2149
      Rename Doc/README.txt to Doc/README.rst #18 0x00000000004ff349 in method_call (func=0x2050d5790, arg=0x20115a5a0, kw=0x0)
      at Objects/classobject.c:319
      Rename Doc/README.txt to Doc/README.rst #19 0x00000000004e4a7f in PyObject_Call (func=0x20115d150, arg=0x20115a5a0, kw=0x0)
      at Objects/abstract.c:2149
      Update link destination of the Mersenne Twister homepage #20 0x000000000042cb66 in slot_tp_call (self=Variable "self" is not available.
      ) at Objects/typeobject.c:5044
      Update readme #21 0x00000000004e4a7f in PyObject_Call (func=0x20113b680, arg=0x20115a5a0, kw=0x0)
      at Objects/abstract.c:2149
      [backport to 3.6] bpo-29474: Improve documentation for weakref.WeakValueDictionary #22 0x00000000004628fb in PyEval_EvalFrameEx (f=0x2071dc030, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4141
      [backport to 3.5] bpo-29474: Improve documentation for weakref.WeakValueDictionary #23 0x000000000046a95c in PyEval_EvalCodeEx (_co=0x2086db6b8, globals=Variable "globals" is not available.
      ) at Python/ceval.c:3350
      bpo-28837: Fix lib2to3 handling of map/zip/filter #24 0x0000000000511ce3 in function_call (func=0x2086de1d0, arg=0x20115d1c8, kw=0x2071dd430)
      at Objects/funcobject.c:629
      [backport to 3.6] bpo-29529: Add .travis.yml to 3.6 branch #25 0x00000000004e4a7f in PyObject_Call (func=0x2086de1d0, arg=0x20115d1c8, kw=0x2071dd430)
      at Objects/abstract.c:2149
      [backport to 3.5] bpo-29529: Add .travis.yml to 3.5 branch #26 0x000000000046456d in PyEval_EvalFrameEx (f=0x2071dde30, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4236
      [backport to 2.7] bpo-29529: Add .travis.yml to 2.7 branch #27 0x000000000046a95c in PyEval_EvalCodeEx (_co=0x2086db490, globals=Variable "globals" is not available.
      ) at Python/ceval.c:3350
      bpo-28556: Various updates to typing #28 0x0000000000511ce3 in function_call (func=0x2086de060, arg=0x20113f420, kw=0x0)
      at Objects/funcobject.c:629
      Removing lengthy year numbers from Copyright #29 0x00000000004e4a7f in PyObject_Call (func=0x2086de060, arg=0x20113f420, kw=0x0)
      at Objects/abstract.c:2149
      Allow up to a 0.01% drop in coverage #30 0x00000000004ff349 in method_call (func=0x2086de060, arg=0x2011411b0, kw=0x0)
      at Objects/classobject.c:319
      bpo-10746: ctypes: Fix PEP 3118 type codes for c_long, c_bool, c_int #31 0x00000000004e4a7f in PyObject_Call (func=0x20115d0d8, arg=0x2011411b0, kw=0x0)
      at Objects/abstract.c:2149
      bpo-29576: Improve some deprecations in the importlib #32 0x000000000042cb66 in slot_tp_call (self=Variable "self" is not available.
      ) at Objects/typeobject.c:5044
      Add Python version since deprecation in base64 methods. #33 0x00000000004e4a7f in PyObject_Call (func=0x201138920, arg=0x2011411b0, kw=0x0)
      at Objects/abstract.c:2149
      bpo-29026: Clarify documentation of time.time #34 0x00000000004628fb in PyEval_EvalFrameEx (f=0x2071dc430, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4141
      bpo-28929: Link the documentation to its source file on GitHub #35 0x000000000046a95c in PyEval_EvalCodeEx (_co=0x2086db6b8, globals=Variable "globals" is not available.
      ) at Python/ceval.c:3350
      [backport to 3.5] bpo-28929: Link the documentation to its source file on GitHub #36 0x0000000000511ce3 in function_call (func=0x2086de1d0, arg=0x20113c498, kw=0x2071dd830)
      at Objects/funcobject.c:629
      [backport to 3.6] bpo-28929: Link the documentation to its source file on GitHub #37 0x00000000004e4a7f in PyObject_Call (func=0x2086de1d0, arg=0x20113c498, kw=0x2071dd830)
      at Objects/abstract.c:2149
      [backport to 2.7] bpo-28929: Link the documentation to its source file on GitHub #38 0x000000000046456d in PyEval_EvalFrameEx (f=0x2071dda30, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4236
      [backport to 3.6] bpo-29438: fixed use-after-free in key sharing dict #39 0x000000000046a95c in PyEval_EvalCodeEx (_co=0x2086db490, globals=Variable "globals" is not available.
      ) at Python/ceval.c:3350
      [backport to 3.5] bpo-29438: Fixed use-after-free in key sharing dict #40 0x0000000000511ce3 in function_call (func=0x2086de060, arg=0x201127ee8, kw=0x0)
      at Objects/funcobject.c:629
      bpo-29521 Fix two minor documentation build warnings #41 0x00000000004e4a7f in PyObject_Call (func=0x2086de060, arg=0x201127ee8, kw=0x0)
      at Objects/abstract.c:2149
      [backport to 3.6] Bpo news support 3.6 #42 0x00000000004ff349 in method_call (func=0x2086de060, arg=0x20113e920, kw=0x0)
      at Objects/classobject.c:319
      [backport to 3.5] Support "bpo-" in Misc/NEWS  #43 0x00000000004e4a7f in PyObject_Call (func=0x208ba78d0, arg=0x20113e920, kw=0x0)
      at Objects/abstract.c:2149
      [backport to 2.7] Change documentation's Show Source link to GitHub #44 0x000000000042cb66 in slot_tp_call (self=Variable "self" is not available.
      ) at Objects/typeobject.c:5044
      bpo-29428: make doctest documentation clearer #45 0x00000000004e4a7f in PyObject_Call (func=0x201138370, arg=0x20113e920, kw=0x0)
      at Objects/abstract.c:2149
      bpo-29463: Add docstring field to some AST nodes. #46 0x00000000004628fb in PyEval_EvalFrameEx (f=0x20de7d830, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4141
      bpo-27122: Fix comment to point to correct issue # #47 0x0000000000468c1a in PyEval_EvalFrameEx (f=0x20de7f830, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4009
      [backport to 3.6] bpo-27122: Fix comment to point to correct issue number (#47) #48 0x0000000000468c1a in PyEval_EvalFrameEx (f=0x20e626830, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4009
      getpass: update docstring #49 0x000000000046a95c in PyEval_EvalCodeEx (_co=0x20189b040, globals=Variable "globals" is not available.
      ) at Python/ceval.c:3350
      [backport to 3.5] bpo-27122: Fix comment to point to correct issue number (#47) #50 0x0000000000511ce3 in function_call (func=0x20449fb28, arg=0x2071d9a30, kw=0x0)
      at Objects/funcobject.c:629
      bpo-28598: Support __rmod__ for RHS subclasses of str in % string formatting operations #51 0x00000000004e4a7f in PyObject_Call (func=0x20449fb28, arg=0x2071d9a30, kw=0x0)
      at Objects/abstract.c:2149
      bpo-29176: Fix name of the _curses.window class #52 0x000000000046456d in PyEval_EvalFrameEx (f=0x200eb9830, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4236
      curses: use tempfile.TemporaryFile for get/putwin #53 0x0000000000468c1a in PyEval_EvalFrameEx (f=0x209c2d830, throwflag=Variable "throwflag" is not available.
      ) at Python/ceval.c:4009
      bpo-29514: Check magic number for bugfix release #54 0x000000000046a95c in PyEval_EvalCodeEx (_co=0x20fc856b8, globals=Variable "globals" is not available.
      ) at Python/ceval.c:3350
      Use current name for macOS #55 0x000000000046ab2b in PyEval_EvalCode (co=Variable "co" is not available.
      ) at Python/ceval.c:767
      Update Copyright dates in README #56 0x000000000048ade7 in run_mod (mod=Variable "mod" is not available.
      ) at Python/pythonrun.c:1783
      bpo-19675: Fixes pool cleanup issue #57 0x000000000048aeee in PyRun_FileExFlags (fp=0x2071bb8e0,
      filename=0x205619690 "Lib/test/test_socket.py.orig", start=257, globals=0x205a01e30,
      locals=0x205a01e30, closeit=1, flags=0x7f7ffffbe5e0) at Python/pythonrun.c:1740
      Renamed whole Mac OS X's to macOS #58 0x000000000048da19 in PyRun_SimpleFileExFlags (fp=0x2071bb8e0,
      filename=0x205619690 "Lib/test/test_socket.py.orig", closeit=1, flags=0x7f7ffffbe5e0)
      at Python/pythonrun.c:1265
      fix typo #59 0x000000000049fe00 in Py_Main (argc=Variable "argc" is not available.
      ) at Modules/main.c:297
      bpo-27494: Fix a 2to3 parser bug (trailing comma) #60 0x0000000000414eaa in main (argc=2, argv=0x7f7ffffbe6a0) at ./Modules/python.c:59

    2. test_sendall_interrupted_with_timeout has an error:
      ======================================================================
      ERROR: test_sendall_interrupted_with_timeout (main.GeneralModuleTests)
      ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "Lib/test/test_socket.py", line 753, in test_sendall_interrupted_with_timeout
        self.check_sendall_interrupted(True)
      File "Lib/test/test_socket.py", line 742, in check_sendall_interrupted
        self.assertRaises(socket.timeout, c.sendall, b"x" * (1024**2))
      File "/usr/ports/pobj/Python-3.2.2/Python-3.2.2/Lib/unittest/case.py", line 557, in assertRaises
        callableObj(*args, **kwargs)
    socket.error: [Errno 0] Error

    ======================================================================

    1. testInterruptedTimeout failed:
      ======================================================================
      FAIL: testInterruptedTimeout (main.TCPTimeoutTest)
      ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "Lib/test/test_socket.py", line 1707, in testInterruptedTimeout
        foo = self.serv.accept()
    socket.timeout: timed out
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "Lib/test/test_socket.py", line 1707, in testInterruptedTimeout
        foo = self.serv.accept()
    Alarm
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "Lib/test/test_socket.py", line 1721, in testInterruptedTimeout
        self.fail("got Alarm in wrong place")
    AssertionError: got Alarm in wrong place

    ======================================================================

    Thanks a lot,

    Remi.

    @rpointel
    Copy link
    Mannequin Author

    rpointel mannequin commented Sep 5, 2011

    I add bt output with gdb 7, to have more informations.

    @vstinner
    Copy link
    Member

    vstinner commented Sep 5, 2011

    I hope that this issue is not related to threads+signals. We got many threads+signals issues on FreeBSD 6.

    @vstinner
    Copy link
    Member

    vstinner commented Sep 6, 2011

    Issue bpo-12903 is similar to this one.

    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Sep 6, 2011

    I hope that this issue is not related to threads+signals. We got many
    threads+signals issues on FreeBSD 6.

    Yep.
    OpenBSD has a really specific pthread implementation (in user-space, using non-blocking I/O), so it might very well be "yet another threads+signals occurrence".

    @rémi
    What happens if you run a code equivalent to test_sendall_interrupted on its own? I mean, if you try something like this:

    """
    import signal, socket
    c, s = socket.socketpair()
    signal.signal(signal.SIGALRM, lambda x,y: 0)
    signal.alarm(1)
    c.sendall(b"x" * (1024**2))
    """

    If it works, you could try creating a dummy thread before setting up the signal handler, something like:
    """
    t = threading.Thread(target=lambda: 0)
    t.start()
    t.join()
    """

    And retry.
    The problem with all those interruption tests (like issue bpo-12903) is that they'll break on many *BSD if another thread is running. Although in this specific case, I suspect that there are no threads running, and we're really encountering a kernel/libc bug (Victor, remember the "funny" bug on FreeBSD where kill(getpid(), <signal>) didn't deliver the signal synchronously after the first thread had been created?).

    @rpointel
    Copy link
    Mannequin Author

    rpointel mannequin commented Sep 6, 2011

    What happens if you run a code equivalent to test_sendall_interrupted on its own? I mean, if you try something like this:

    Hi, it blocks too:

    $ gdb -args ./python
    [...]
    (gdb) run
    Starting program: /usr/ports/pobj/Python-3.2.2/Python-3.2.2/python 
    Python 3.2.2 (default, Sep  5 2011, 21:21:34) 
    [GCC 4.2.1 20070719 ] on openbsd5
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import signal, socket
    >>> c, s = socket.socketpair()
    >>> signal.signal(signal.SIGALRM, lambda x,y: 0)
    0
    >>> signal.alarm(1)
    0
    >>> [New process 28830]
    c.sendall(b"x" * (1024**2))
    ^C
    Program received signal SIGINT, Interrupt.
    Cannot access memory at address 0x98
    (gdb) bt
    #0  0x000000020125678a in poll () from /usr/lib/libc.so.60.1
    #1  0x000000020619b4aa in _thread_kern_poll (wait_reqd=<value optimized out>)
        at /usr/src/lib/libpthread/uthread/uthread_kern.c:780
    #2  0x000000020619c3a8 in _thread_kern_sched (scp=0x0)
        at /usr/src/lib/libpthread/uthread/uthread_kern.c:382
    #3  0x0000000206190ade in sendto (fd=9, msg=0x2032d6020, len=1044480, flags=0, to=0x0, to_len=0)
        at /usr/src/lib/libpthread/uthread/uthread_sendto.c:63
    #4  0x00000002105f670a in sock_sendall ()
       from /usr/ports/pobj/Python-3.2.2/Python-3.2.2/build/lib.openbsd-5.0-amd64-3.2/_socket.so
    #5  0x000000020668b172 in PyEval_EvalFrameEx () from /usr/local/lib/libpython3.2m.so.1.0
    #6  0x000000020668bf66 in PyEval_EvalCodeEx () from /usr/local/lib/libpython3.2m.so.1.0
    #7  0x000000020668c22b in PyEval_EvalCode () from /usr/local/lib/libpython3.2m.so.1.0
    #8  0x00000002066a93d7 in run_mod () from /usr/local/lib/libpython3.2m.so.1.0
    #9  0x00000002066abcae in PyRun_InteractiveOneFlags () from /usr/local/lib/libpython3.2m.so.1.0
    #10 0x00000002066abf3e in PyRun_InteractiveLoopFlags () from /usr/local/lib/libpython3.2m.so.1.0
    #11 0x00000002066ac04c in PyRun_AnyFileExFlags () from /usr/local/lib/libpython3.2m.so.1.0
    #12 0x00000002066bc9f4 in Py_Main () from /usr/local/lib/libpython3.2m.so.1.0
    #13 0x0000000000400e75 in main ()

    Thanks for your help,

    Remi.

    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Sep 6, 2011

    Hi, it blocks too:

    Oops, I just realized there was a typo in the sample test.
    The signal handler should be
    lambda x,y: 1/0

    and not

    lambda x,y: 0

    @vstinner
    Copy link
    Member

    vstinner commented Sep 6, 2011

    I tried the following script on OpenBSD 5 with Python 3.3:
    -----------
    import signal
    import sys

    s = signal.SIGALRM
    signal.signal(s, lambda x,y: 1/0)
    signal.alarm(1)
    signal.siginterrupt(s, True)
    sys.stdin.read()

    The C signal handler is called, but the system call (read in this case) is not interrupted.

    @vstinner
    Copy link
    Member

    vstinner commented Sep 6, 2011

    I tried the following script on OpenBSD 5 with Python 3.3: ...

    Bad news: the script doesn't hang if Python is build without threads.

    Short C program to test interrupted syscalls:
    -------------                                                                                                    
    #include <signal.h>
    #include <stdio.h>
    #include <pthread.h>
    
    void
    handler(int signum)
    {
    printf("HANDLER!\n");
    }
    
    void _noop()
    {
    }
    
    int main()
    {
    int s = SIGALRM;
    char buffer[1024];
    int n;
    static int dummy = 0;

    pthread_t thread1;
    pthread_create(&thread1, NULL, (void *) _noop, &dummy);
    pthread_join(thread1, NULL);

    signal(s, handler);
    siginterrupt(s, 1);
    alarm(1);
    printf("read...\n");
    n = read(0, buffer, 1024);
    printf("read->%i\n", n);
    return 0;
    }

    read() is interrupted after 1 second, it works.

    @vstinner
    Copy link
    Member

    vstinner commented Sep 6, 2011

    Oh, siginterrupt(SIGALRM, 0) doesn't work in a program linked to pthread. Example:
    --------

    #include <signal.h>
    #include <stdio.h>
    
    void
    handler(int signum)
    { printf("HANDLER!\n"); }
    
    int main()
    {
    int s = SIGALRM;
    char buffer[1024];
    int n;
    
    signal(s, handler);
    siginterrupt(s, 0);
    alarm(1);
    printf("read...\n");
    n = read(0, buffer, 1024);
    printf("read->%i\n", n);
    return 0;
    }

    This program ends after 1 second with "read->-1" if it is linked to pthread (bug!), it hangs if it is not linked to pthread (ok).

    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Sep 6, 2011

    The C signal handler is called, but the system call (read in this case)
    is not interrupted.

    That's what I thought...

    Bad news: the script doesn't hang if Python is build without threads.

    Makes sense. When linked with pthread, all I/O syscalls are actually non-blocking.

    read() is interrupted after 1 second, it works.

    Hmmm...
    Does it still work if you don't a create thread beforehand?

    Also, one difference is that Python uses sigaction to setup the signal handler. There might be subtle semantics change/bugs between signal/sigaction.

    Oh, siginterrupt(SIGALRM, 0) doesn't work in a program linked to
    pthread.

    You could try with sigaction/SA_RESTART.

    But OpenBSD's pthread implementation has severe limitations/bugs.

    @vstinner
    Copy link
    Member

    vstinner commented Sep 6, 2011

    > read() is interrupted after 1 second, it works.
    Does it still work if you don't a create thread beforehand?

    Yes, the read() is also interrupted as expected if no thread is created.

    one difference is that Python uses sigaction to setup the signal handler

    If the handler is installed using the following code, read() is interrupted:
    ----------
    sigemptyset(&sa.sa_mask);
    sa.sa_handler = handler;
    sa.sa_flags = 0;
    sigaction(SIGALRM, &sa, NULL);
    ----------

    Using sa.sa_flags=SA_RESTART, read() hangs (it is not interrupted). Python uses sigaction with flags=0.

    You could try with sigaction/SA_RESTART.

    Using SA_RESTART, read() is not interrupted. But if the program is linked to pthread, read() is always interrupted: with sa_flags=0 or sa_flags=SA_RESTART.

    But OpenBSD's pthread implementation has severe limitations/bugs.

    rthread doc contains:

    "Future work:

    Quite simply, signal handling is one the most complicated aspects of threads to get right. (...)"

    http://www.openbsd.org/papers/eurobsd2005/tedu-rthreads.pdf

    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Sep 7, 2011

    Using SA_RESTART, read() is not interrupted. But if the program is linked to pthread, read() is always interrupted: with sa_flags=0 or sa_flags=SA_RESTART.

    Ouch...

    > But OpenBSD's pthread implementation has severe limitations/bugs.

    rthread doc contains:

    "Future work:

    Quite simply, signal handling is one the most complicated aspects of threads to get right. (...)"

    This paper dates back to 2005, I was hoping they would have solved
    this by now...

    As for the original problem, IIUC you don't reproduce it with your C
    test code...
    It might be due to a subtle difference in the way Python is built
    (like POSIX_SOURCE...), but it's hard to tell...

    @vstinner
    Copy link
    Member

    vstinner commented Sep 8, 2011

    It looks like Python cannot do much to workaround OpenBSD issues. IMO the best fix is just to skip these tests on OpenBSD, until OpenBSD handles correctly signals in programs linked to pthread. The same "fix" can be used for bpo-12903.

    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Sep 9, 2011

    It looks like Python cannot do much to workaround OpenBSD issues. IMO the best fix is just to skip these tests on OpenBSD, until OpenBSD handles correctly signals in programs linked to pthread. The same "fix" can be used for bpo-12903.

    Agreed.

    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Oct 29, 2011

    Rémi, do you want to submit a patch to skip those tests on OpenBSD?

    @rpointel
    Copy link
    Mannequin Author

    rpointel mannequin commented Feb 28, 2012

    I think we could close this bug because it's du to the pthread library on OpenBSD and not Python.
    We are switching to rthreads and I can't reproduce this bug.

    Thanks for your help and sorry for the delay.

    @neologix
    Copy link
    Mannequin

    neologix mannequin commented Feb 28, 2012

    I think we could close this bug because it's du to the pthread library
    on OpenBSD and not Python.

    Indeed.

    @neologix neologix mannequin added invalid type-bug An unexpected behavior, bug, or error labels Feb 28, 2012
    @neologix neologix mannequin closed this as completed Feb 28, 2012
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant