-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
python3 resource.setrlimit strange behaviour under macOS #78783
Comments
Consider the following code:
Running this under macOS with python 3.6.5 gives the following exception:
Nevertheless, when using python 2.7.10 under the same environment, this code works perfectly without exceptions being thrown. Additionally, neither of these operations fail under the same circumstances :
I have also tried to run the above-mentioned python script on linux, also it does not generate exceptions both on python2 (2.7.10) & python3 (3.6.5). |
I get the same error, also with python3.7. Both for homebrew and a python.org installer. |
I can repro it with a given sample file
Similar settings were added to Python in 335ab5b66f4 |
Thanks for the repro! It did help for pinpointing the issue. So I took a little spare time and dived into xnu kernel code, here is my assumption based on what I found (N.B. : My assumption comes from a simple experiment and a brief skim of the source code within 15 minutes or less, it could be seriously wrong since I'm not an expert of XNU kernel, and I currently don't have the time to build and debug it.) : In bsd/kern/kern_resource.c, there's a function
As we can see, the kernel will try to
As we can see, it seems that the kernel tried to bsd/kern/kern_exec.c, in
So that comes my conclusion: if the binary has a specified default stack size, this |
https://bugs.python.org/issue34602 may be relating to this. |
I guess Inada Naoki was to say https://bugs.python.org/issue36432 in the last comment. |
Thanks for the analyses everyone! Also see the discussion in duplicate bpo-36432. I was never able to reproduce the failure on earlier versions of macOS but then it seemed to become a hard failure with the release of 10.14.4. I haven't gone back and tried running the tests on all supported older versions with this reversion in place but those I have did not exhibit any new failures. So we should keep an eye open for reports of segfaults running tests as originally reported in bpo-18075. But better that then not being able to run any tests. "Fixed" in 3.8.0a4, 3.7.4, and 3.6.9 (to allow tests to be run on macOS) by reverting the change for bpo-18075. |
Now there are such reports for 3.7.4rc1, at least. Release builds seem to be OK but at least four tests now fail on macOS 10.14.5 when built --with-pydebug: test_exceptions test_json test_logging test_sys test_traceback. Plus, changing the interpreters stack size can inhibit use of dtrace. There are really two attempts at dealing with macOS's small default stack size. The original workaround, dating back to 2002-12-02 (bb48465 !!) added the runtime calls in regrtest to change RLIMIT_STACK. Years later, a different approach was taken in the original change for bpo-18075 (335ab5b) by increasing the default stack size when building the interpreter rather than at runtime. So, I *think* that means that the original regrtest runtime workaround is really no longer needed. So I think we should take the opposite approach to what I originally merged back in April, that is, we should go back to building the interpreter with the increased stack size and remove the ancient regrtest workaround attempt: that's what was failing here anyway. The only place in the source base that resource.RLIMIT_STACK is used, outside of its functional test, is the old regrtest workaround. It's still a bit of a mystery as what has changed in 3.8 that seems to not hit the stack size limit but these kind of test failures on macOS have always been dependent on other factors, including compiler version and options. I'd like to get this into 3.8.0b2 and 3.7.4rc2 ao I'm temporarily making it a "release blocker"; the PR will follow momentarily. |
My understanding of the resolution of this ticket is that it is still not possible to use setrlimit with RLIMIT_STACK to raise the soft stack limit. Is that correct? In that case, the original bug report still seems valid and unresolved (and indeed, I am porting a project from Python 2.7 to Python 3.9 and on macOS it fails because it cannot raise the stack limit). |
Yes, the code in msg324731 still fails. We're still using the mechanism described in msg324818, but with a larger stack size for some builds. It is rather annoying that -Wl,-stack_size,NNNN sets a hard limit on the stack size, rather than overriding the soft limit. I guess we could change the startup code for the interpreter executable (Py_Main or related code) to set the RLIMIT_STACK to a larger value when it is too small, that way applications can still pick a different (and in particular larger) value. @ned.deily, @lukasz.langa: reopen this issue or open a new one? |
Since there are so many iterations on this issue already, I think a new issue would be better. |
hi! sorry if i'm not being blind but is the new issue linked somewhere? i just ran into the same issue on python 3.12 😭
|
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: