lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.37k stars 157 forks source link

Prevent calling `abort` while handling the `SIGABRT` signal #2626

Closed Vipul-Cariappa closed 3 months ago

Vipul-Cariappa commented 3 months ago

We register loc_abort_callback_print_stack as a callback on the SIGABRT signal and loc_segfault_callback_print_stack on the SIGSEGV signal. (reference: https://github.com/lcompilers/lpython/blob/main/src/libasr/stacktrace.cpp#L530-L531)

Tracing the flow of function calls: loc_abort_callback_print_stack and loc_segfault_callback_print_stack calls get_stacktrace (reference: https://github.com/lcompilers/lpython/blob/main/src/libasr/stacktrace.cpp#L524 & https://github.com/lcompilers/lpython/blob/main/src/libasr/stacktrace.cpp#L516) get_stacktrace calls get_local_addresses (reference: https://github.com/lcompilers/lpython/blob/main/src/libasr/stacktrace.cpp#L537) get_local_addresses calls get_local_address (reference: https://github.com/lcompilers/lpython/blob/main/src/libasr/stacktrace.cpp#L561) get_local_address calls abort. (reference: https://github.com/lcompilers/lpython/blob/main/src/libasr/stacktrace.cpp#L142)

So while handling SIGABRT we end up regenerating SIGABRT and the cycle repeats. To prevent this, I have changed the abort() to exit(1) to immediately exit.

I observed this while working on #2564 and #2595.

Shaikh-Ubaid commented 3 months ago

I think this is a Great catch! Thanks! I am curious how did you debug this?