-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
tests/thread/thread_stacksize1: Fix crash on certain platforms #5784
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
Conversation
Also wondering why tests aren't formatted with black like everything else is now? |
I'm not able to reproduce this problem (but I do see that it fails sometimes on Travis CI). What arch/OS can you reproduce it on? It'd be good to try and fix this properly (if possible) rather than adjust the test. |
I can reproduce the issue using the unix coverage variant on Mac. (This can also be seen in #5773 where that build is added to CI). Based on the discussion in #2927, it sounds like having too small of a stack can lead to this error and debug builds (and therefore coverage builds) require a much bigger stack. It is the test itself that is setting a 2K stack, so I don't think the problem is elsewhere. If there was a way to detect coverage builds at runtime, then I suppose we could make a better test condition, but I think what I currently have here seems reasonable enough. |
Ok, thanks for the hint, I can now also reproduce it on Mac. And I have a different fix: the problem seems to be that on Mac the minimum stack size allowed by pthreads (the variable ``) is much less than on Linux, and so the subtraction of 8192 bytes (to give room to detect a stack overflow) takes the stack size down to 0. To fix this I did: --- a/ports/unix/mpthreadport.c
+++ b/ports/unix/mpthreadport.c
@@ -221,7 +221,11 @@ void mp_thread_create(void *(*entry)(void *), void *arg, size_t *stack_size) {
// adjust stack_size to provide room to recover from hitting the limit
// this value seems to be about right for both 32-bit and 64-bit builds
- *stack_size -= 8192;
+ if (*stack_size >= 2 * 8192) {
+ *stack_size -= 8192;
+ } else {
+ *stack_size /= 2;
+ }
// add thread to linked list of all threads
thread_t *th = malloc(sizeof(thread_t)); And this seems to get all thread tests passing on Mac. |
Thanks for the insight. I will update the PR. |
The test tests/thread/thread_stacksize1.py sometimes crashes with a segmentation fault because of an uncaught NLR jump. $ ./ports/unix/micropython-coverage tests/thread/thread_stacksize1.py 0 0 True 0 Unhandled exception in thread started by FATAL: uncaught NLR 0x7fc316d06500 Using a debugger, this exception message was found to be: "maximum recursion depth exceeded" The stack size adjustment for detecting stack overflow in threads was not taking into account that the requested stack size could be < 8k in which case, the subtraction would overflow. This is fixed by ensuring that the adjustment can't be more than the available size. Suggested-by: @dpgeorge
9323e12
to
d25f5d4
Compare
updated |
Thanks a lot! Merged in 5e6cee0 |
vectorio contains(x, y)
The test tests/thread/thread_stacksize1.py sometimes crashes with a segmentation fault because of an uncaught NLR jump.
Using a debugger, this exception message was found to be:
To fix this, we add some additional checks in the test to give a bigger stack to "desktop" platforms that need it to avoid this crash.