EXC_BAD_ACCESS and overflowed stack when value is returned

This happens on Rust 1.59 and Rust 1.60, not sure if the toolchain is related. I use Tokio 1.17.

I have a very weird case in which I get an error but I have no clue why. A result is returned and then it crashes, I am unable to locate why. It worked before, but I am not sure why it suddenly doesn't work anymore (it is a test and I didn't run it in a while).

I can not give you a minimal reproduction project, because it works in projects where I try to reproduce it. I can however give you information about my own project where it fails.

This is the code snippet where I return the result of a method call

When using breakpoints, I can verify that the calling method receives the return value
(see comment, I can only post 1 image...)

However, when I want to continue, it crashes:
(see comment, I can only post 1 image...)

This is in the logs when I use breakpoints:

Exception: EXC_BAD_ACCESS (code=2, address=0x70000bff9278)

When I don't do breakpoints (just run the application without debug mode), this error is logged:

Apr 13 09:39:33.793 DEBUG message_processor::messages::request_processor: 222222222

thread 'tokio-runtime-worker' has overflowed its stack
fatal runtime error: stack overflow

I don't know why it overflowes its stack. I tried increasing the stack size by a lot, but that didn't work:
thread_stack_size(10 * 1024 * 1024)

It is also strange: a result is returned from a method and then this error is logged.

The logging (the 2's) is showing us that the method call was successfully and it returns the result. The 3's are not logged, indicating something is going wrong when trying to use the returned value. In the screenshots I provided, you can read the print statements.

I am not sure how to debug this further. Any suggestions?

It sounds like you are doing infinite recursion somewhere.

1 Like

After the fn returns, it is crashing, it is not doing infinite recursion

It seems like it crashes between starting to drop all in scope variables and actually returning. drop_in_place is a magic function that is replaced with the code necessary to drop a value.

1 Like

Alright after hours of debugging, I noticed I used the tokio::test, without a thread stack size. I did only change the stack size in non-test code. After I ran the test with an increased stack size, things worked. Well this took me my whole day :frowning:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.