Skip to content

3.15.0b2 test failures on FreeBSD 15.1-RC2 arm.armv7: test_os, test_wait3 #151019

Closed as not planned

Description

@mandree

Bug report

Bug description:

Trying to narrow down what are 32-bit failures and what are i386 failures, I compiled Python 3.15.0b2 on FreeBSD 15.1-RC2 arm.armv7 and got these make test failures. This is the console log with colours removed, only showing the verbose mode output from re-runs, without those reported previously in #151007, #150984 or #150982.

Re-running test_wait3 in verbose mode (matching: test_wait3_rusage_initialized)                                                                                                                                                                             
test_wait3_rusage_initialized (test.test_wait3.Wait3Test.test_wait3_rusage_initialized) ... FAIL                                                                                                                                                            
                                                               
======================================================================                                                                                                                                                                                      
FAIL: test_wait3_rusage_initialized (test.test_wait3.Wait3Test.test_wait3_rusage_initialized)                                                                                                                                                               
----------------------------------------------------------------------                                                                                                                                                                                      
Traceback (most recent call last):                                                                                                                                                                                                                          
  File "/wrkdirs/usr/ports/lang/python315/work/Python-3.15.0b2/Lib/test/test_wait3.py", line 42, in test_wait3_rusage_initialized                          
    self.assertEqual(0, status)                                                                                                                                                                                                                             
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^                                                                                                                                                                                                                             
AssertionError: 0 != -65536                                                                                                                                                                                                                                 
                                                                                                                              
----------------------------------------------------------------------                                                                                                                                                                                      
Ran 1 test in 0.044s                                                                                                          
                                                                                                                              
FAILED (failures=1)                                                                                                           
test test_wait3 failed   


Re-running test.test_os.test_os in verbose mode (matching: test_headers_overflow_32bits, test_trailers_overflow_32bits)                                                                                                                                     
test_headers_overflow_32bits (test.test_os.test_os.TestSendfile.test_headers_overflow_32bits) ... ERROR                                                                                                                                                     
test_trailers_overflow_32bits (test.test_os.test_os.TestSendfile.test_trailers_overflow_32bits) ... ERROR                                                                                                                                                   
                                                                                                                                                                                                                                                            
======================================================================                                                                                                                                                                                      
ERROR: test_headers_overflow_32bits (test.test_os.test_os.TestSendfile.test_headers_overflow_32bits)                                                                                                                                                        
----------------------------------------------------------------------                                                                                                                                                                                      
Traceback (most recent call last):                             
  File "/wrkdirs/usr/ports/lang/python315/work/Python-3.15.0b2/Lib/asyncio/runners.py", line 127, in run                                                                                                                                                    
    return self._loop.run_until_complete(task)                                                                                                                                                                                                              
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^                                                                                                                                                                                                              
  File "/wrkdirs/usr/ports/lang/python315/work/Python-3.15.0b2/Lib/asyncio/base_events.py", line 724, in run_until_complete                                                                                                                                 
    return future.result()                                                                                                                                                                                                                                  
           ~~~~~~~~~~~~~^^                                                                                                                                                                                                                                  
  File "/wrkdirs/usr/ports/lang/python315/work/Python-3.15.0b2/Lib/test/test_os/test_os.py", line 3792, in test_headers_overflow_32bits                                                                                                                     
    self.server.handler_instance.accumulate = False                                                                                                                                                                                                         
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                              
AttributeError: 'Server' object has no attribute 'handler_instance'                                                                                                                                                                                         
                                                                                                                              
======================================================================                                                        
ERROR: test_trailers_overflow_32bits (test.test_os.test_os.TestSendfile.test_trailers_overflow_32bits)                        
----------------------------------------------------------------------                                                                                                                                                                                      
Traceback (most recent call last):                                                                                                                                                                                                                          
  File "/wrkdirs/usr/ports/lang/python315/work/Python-3.15.0b2/Lib/asyncio/runners.py", line 127, in run                                                                                                                                                    
    return self._loop.run_until_complete(task)                                                                                                                                                                                                              
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^                                                                                
  File "/wrkdirs/usr/ports/lang/python315/work/Python-3.15.0b2/Lib/asyncio/base_events.py", line 724, in run_until_complete                                                                                                                                 
    return future.result()                                                                                                    
           ~~~~~~~~~~~~~^^                                                                                                    
  File "/wrkdirs/usr/ports/lang/python315/work/Python-3.15.0b2/Lib/test/test_os/test_os.py", line 3801, in test_trailers_overflow_32bits                                                                                                                    
    self.server.handler_instance.accumulate = False           
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                              
AttributeError: 'Server' object has no attribute 'handler_instance'

----------------------------------------------------------------------
Ran 2 tests in 0.048s

FAILED (errors=2)
test test.test_os.test_os failed

CPython versions tested on:

3.15

Operating systems tested on:

Other

Linked PRs

Activity

  1. added
    type-bug
    on Jun 6, 2026
  2. added
    tests
    on Jun 6, 2026
  3. vstinner commented on Jun 8, 2026

    @vstinner
    Member

    test_headers_overflow_32bits() and test_trailers_overflow_32bits() are only run some operating systems (ex: not on Linux) and only on 32-bit systems. The last reference to handler_instance was in the commit 3ae975f replacing asyncore with asyncio in test_os.

  4. vstinner commented on Jun 8, 2026

    @vstinner
    Member

    I managed to build Python on FreeBSD x64-64 in 32-bit using:

    ./configure --with-pydebug CFLAGS=-m32 LDFLAGS=-m32

    I had to disable extension modules which depend on C libraries (not available in 32-bit mode). I created Modules/Setup.local with the following contents:

    # Edit this file for local setup changes
    
    *disabled*
    _decimal _decimal/_decimal.c
    _zstd _zstd/_zstdmodule.c _zstd/zstddict.c _zstd/compressor.c _zstd/decompressor.c
    _remote_debugging _remote_debugging/module.c _remote_debugging/gc_stats.c _remote_debugging/object_reading.c _remote_debugging/code_objects.c _remote_debugging/frames.c _remote_debugging/frame_cache.c _remote_debugging/threads.c _remote_debugging/asyncio.c _remote_debugging/binary_io_writer.c _remote_debugging/binary_io_reader.c _remote_debugging/subprocess.c _remote_debugging/interpreters.c
    readline readline.c
    _ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/stgdict.c _ctypes/cfield.c
    _ctypes_test _ctypes/_ctypes_test.c
    

    I wrote PR gh-151087 to fix test_os on 32-bit FreeBSD.

  5. added a commit that references this issue on Jun 8, 2026
  6. vstinner commented on Jun 8, 2026

    @vstinner
    Member

    I'm unable to reproduce the test_wait3 issue with my setup.

  7. mandree commented on Jun 8, 2026

    @mandree
    Author

    I am trying (have been for the past like hour or so) to debug this, though on a non-debug build.
    What I can say is that

    • ktrace/kdump does not seem to work in my armv7 jail (hosted on aarch64),
    • There must be something specifically armv7 because I don't see the same on i386,
    • running truss ./python masks the bug

    I would appreciate a pointer to example code how to emit debug information from Module/posixmodule.c. I tried fopen("filename", "w"), fopen("/tmp/filename", "w") but didn't ever see this attempt appear in truss, from os_wait3_impl. I'd just run "gmake -j40" top-level in the build directory and it seemed to re-build quite a few things, but I may need to install them, too for the test-suite? so ... gmake altinstall?

  8. added 3 commits that reference this issue on Jun 8, 2026
  9. mandree commented on Jun 8, 2026

    @mandree
    Author

    EDIT: I am withdrawing this comment, see later comment for why.

    I think the test_wait3 test is off and expecting that implementations behave in a certain way, OTOH wait3/wait4 interfaces are deprecated, so it's a bit like fighting history and may not be too useful going forward, and my proposal is if wait3() or wait4() came back without a PID, IOW no process reported status, to not only zero out the struct rusage but also the status, for consistency.

    The offending line of the test is marked below in Exhibit 1, and I am not sure that the original bug report bpo-36279 referenced by it https://bugs.python.org/issue36279 and the response are useful, 682107c but anyways, that's been there since Python 3.8 or so.

    On FreeBSD and Linux; the documentation on wait3 or waitpid isn't perfectly clear on whether status is being filled in in case wait3(...WNOHANG...) returns 0 (which is a success), because no child had previously queued status from its termination or being stopped;
    the waitid documentation on the respective OSes suggest that information isn't filled in (but waitid has a different return interface), and ARMv7 appears to be ... special, at least when running in emulation on an Aarch64 host.

    PROPOSAL: The easy way to mask this idiosyncrasy is in the wait_helper() place where we wipe out the rusage structure on pid == 0, to also zero status. The exit/signal status of something that doesn't exist isn't meaningful, so let's not pretend. With the patch shown in Exhibit 2, test_wait3 passes for me on the offending FreeBSD ARMv7 (running in a jail hosted on FreeBSD Aarch64).

    Exhibit 1, snipped from Lib/tests/test_wait3.py:

        def test_wait3_rusage_initialized(self):
            # Ensure a successful wait3() call where no child was ready to report
            # its exit status does not return uninitialized memory in the rusage
            # structure. See bpo-36279.
            args = [sys.executable, '-c', 'import sys; sys.stdin.read()']
            proc = subprocess.Popen(args, stdin=subprocess.PIPE)
            try:
                pid, status, rusage = os.wait3(os.WNOHANG)
                self.assertEqual(0, pid)
                self.assertEqual(0, status)  # <- OFFENDER
                self.assertEqual(0, sum(rusage))
            finally:
                proc.stdin.close()
                proc.wait()

    Exhibit 2, patch for Module/posixmodule.c:

    --- Modules/posixmodule.c.orig	2026-06-02 15:28:41 UTC
    +++ Modules/posixmodule.c
    @@ -10457,8 +10457,10 @@ wait_helper(PyObject *module, pid_t pid, int status, struct rusage *ru)
     
         // If wait succeeded but no child was ready to report status, ru will not
         // have been populated.
    +    // Also, status may not be reliable on some implementations, zero it out.
         if (pid == 0) {
             memset(ru, 0, sizeof(*ru));
    +        status = 0;
         }
     
         struct_rusage = PyImport_ImportModuleAttrString("resource", "struct_rusage");
  10. changed the title [-]3.15.0b2 test failures on FreeBSD 15.1-RC2 arm.armv7[/-] [+]3.15.0b2 test failures on FreeBSD 15.1-RC2 arm.armv7: test_os, test_wait3[/+] on Jun 8, 2026
  11. vstinner commented on Jun 9, 2026

    @vstinner
    Member

    I'm not fully comfortable with changing wait_helper() if os.wait3() behavior is currently the same on all platforms tested by Python. Moreover, os.wait3() initializes the status to 0. At least, if you make this change, I would prefer to make it specific to FreeBSD and add a comment to explain that the bug occurs on armv7.

  12. mandree commented on Jun 9, 2026

    @mandree
    Author

    Understood, I re-read your comment, my comment, and the code, and have withdrawn my earlier statement that the test be off.

    Let's instead put this to the FreeBSD-ARM guys to have a first look.
    https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295965 also has a shorter reproducer program that does not require the full Python.

    Just to pick everyone up who joins this test debugging party late:
    The current impression is that FreeBSD 15.1-RC2 on ARMv7 messes up the wait3(&status...) in the use case shown below, I added inline comments with //// so I can comment.

    So we agree that at (1), Python essentially sets status = 0 (the whole macro decoration around that is for other systems that use a union and not a bit-masked integer, for process exit status codes) and (2) FreeBSD on certain combination of system and CPU/arch changes status to a 0xFFFF0000 bit pattern, which is -65536, and I read @vstinner's reaction such that this is odd and works most everywhere else.

    Direct permalink to code with explanatory source code comments:

    #ifdef HAVE_WAIT3

    // Modules/posixmodule.c:10526 ff.
    static PyObject *
    os_wait3_impl(PyObject *module, int options)
    /*[clinic end generated code: output=92c3224e6f28217a input=8ac4c56956b61710]*/
    {
        pid_t pid;
        struct rusage ru;
        int async_err = 0;
        WAIT_TYPE status;
        WAIT_STATUS_INT(status) = 0;    //// (1) status initialized here
    
        do {
            Py_BEGIN_ALLOW_THREADS
            pid = wait3(&status, options, &ru);    //// (2) status clobbered here on specific system.
            Py_END_ALLOW_THREADS
        } while (pid < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));
  13. vstinner commented on Jun 10, 2026

    @vstinner
    Member

    Ok, so as I expected, it was a bug in the FreeBSD kernel. It just has been fixed in CURRENT: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295965#c10.

    I close this issue. I don't think that it's worth it to workaround this FreeBSD bug in the Python os module. You can carry a patch until the fix land in your kernel.

  14. mandree commented on Jun 10, 2026

    @mandree
    Author

    Agreed. Thanks for insisting on finding the actual error location.

    If I am reading the kernel fix right, it was in the 64-bit kernel's emulation layer that executes 32-bit code on 64-bit systems (and jails are somewhat thin separation in that they are not virtual machines, they share the host kernel), so might not even hit real 32-bit ARMv7 systems.

  15. vstinner commented on Jun 10, 2026

    @vstinner
    Member

    If I am reading the kernel fix right, it was in the 64-bit kernel's emulation layer that executes 32-bit code on 64-bit systems (and jails are somewhat thin separation in that they are not virtual machines, they share the host kernel), so might not even hit real 32-bit ARMv7 systems.

    Correct. "real 32-bit ARMv7 systems" should not be affected.

  16. added a commit that references this issue on Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-freebsdteststype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions