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
FreeBSD: test_threading: test_recursion_limit() crash with SIGSEGV and create a coredump #82087
Comments
On my FreeBSD 12.0-RELEASE-p10 VM, test_threading.test_recursion_limit() does crash with SIGSEGV and create a coredump. vstinner@freebsd$ ./python -m test -v test_threading -m test_recursion_limit ====================================================================== Traceback (most recent call last):
File "/usr/home/vstinner/python/master/Lib/test/test_threading.py", line 1086, in test_recursion_limit
self.assertEqual(p.returncode, 0, "Unexpected error: " + stderr.decode())
AssertionError: -11 != 0 : Unexpected error: Ran 1 test in 6.017s FAILED (failures=1) == Tests result: FAILURE == 1 test failed: Total duration: 7 sec 284 ms |
I used git bisect in the 3.8 branch and I found this change: commit 8399641
Before this change, the test was skipped on FreeBSD: ... |
The crash start to occur with a Python callstack depth larger than 750. It doesn't crash with setrecursionlimit(750). See attached stack.py. Example: vstinner@freebsd$ ./python stack.py 750 10240 It seems like calling _thread.stack_size(s) doesn't help: vstinner@freebsd$ ./python stack.py 1000 10240 -- I see different options:
On macOS, configure.ac uses a stack of 8 MiB:
|
Oh, my script called _thread.stack_size() to read the stack size, but that doesn't work: calling _thread.stack_size() sets the stack size to 0 again. stack2.py is the fixed script. It seems like the test works with a stack of 8 MiB and the default recursion limit of 1000 Python frames: vstinner@freebsd$ ./python stack.py 1000 4096 vstinner@freebsd$ ./python stack.py 1000 8192 So the problem is that the FreeBSD default thread stack size is too small. |
I'd increase the default stack size for FreeBSD as well. AFAIK FreeBSD uses clang as the default compiler like macOS, and it is therefore likely that the two platforms have similar stack usage for similar code. BTW. I can provide a PR for this but cannot easily test on FreeBSD. |
On my FreeBSD 12.0 VM, /usr/bin/ld is a symbolic link to ld.ldd: it's the LLVM linker called "LLD": I modified manually Makefile to give 16 MiB stack to the main thread using: LINKFORSHARED= -Wl,--export-dynamic "-Wl,-z" "-Wl,stack-size=0x1000000" I added manually the following to Python/thread_pthread.h to give 16 MiB stack to thread: #undef THREAD_STACK_SIZE
#define THREAD_STACK_SIZE 0x1000000 Using that, the RecurisionError is raised at a depth of 1000 Python function calls: before we exhaust the C stack. -- The syntax used in configure.ac doesn't work with LLD. I get such error: cc -pthread -Wl,--export-dynamic -Wl,-stack_size,1000000 -o Programs/_testembed Programs/_testembed.o libpython3.9d.a -lcrypt -ldl -lutil -lm -lm /usr/bin/ld: error: cannot open 1000000: No such file or directory |
See the android related issue bpo-38852. |
|
Something seems to have changed in the meantime, because all tests now pass for me on both supported FreeBSD production releases (12.3 and 13.0) and the main branch (all under amd64). Here is the output.
Running
|
The crash occurred on Python built in debug mode: |
I can no longer reproduce the issue. Maybe it's because this test only use Python-to-Python function calls which uses way less stack memory in Python 3.11: https://docs.python.org/dev/whatsnew/3.11.html#inlined-python-function-calls I close the issue. |
Thanks. FWIW now, I tested with the python 3.8 configure arguments below and the tests pass.
|
I didn't intend to post the shell variable in the |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: