Bug #85076 handle_fatal_signal calls unsafe function pthread_getspecific - it can crash

Submitted: 20 Feb 2017 7:14
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Errors Severity:S3 (Non-critical)
Version:5.6 OS:Linux (x64)
Assigned to: CPU Architecture:Any

[20 Feb 2017 7:14] Shane Bester
Description:
This is a followup to https://bugs.mysql.com/bug.php?id=54082
Signal handler can crash here:

5.6.19:
(gdb) bt
#0  in __GI___pthread_getspecific (key=3) at pthread_getspecific.c:56
#1  in _current_thd () at ./sql/mysqld.h:749
#2  in handle_fatal_signal (sig=11) at ./sql/signal_handler.cc:152
#3  <signal handler called>
#4  in __GI___pthread_getspecific (key=3) at pthread_getspecific.c:56
#5  in _current_thd () at ./sql/mysqld.h:749
#6  in decimal_operation_results (result=2) at ./sql/my_decimal.cc:48
#7  in check_result (mask=30, result=816) at ./sql/my_decimal.h:224
#8  in my_decimal2int at ./sql/my_decimal.h:379
#9  in user_var_entry::val_int at ./sql/item_func.cc:4845
#10 0x0000000000099023 in ?? ()
#11 0x0000000000000000 in ?? ()

The line of code crashing is :     THD *thd=current_thd;

How to repeat:
not readily repeatable. happens randomly on crashes.

Suggested fix:
I am really not sure, but this is documenting the problem exists..
[20 Feb 2017 7:14] Shane Bester
fwiw,  backtrace() shouldn't be called either as it's not signal-safe, but I think we need to use this for ease of use to study log files.
[20 Feb 2017 7:21] Shane Bester
here is an example of backtrace() crashing in the signal handler:

(gdb) bt
#0  in ?? () from /lib64/libgcc_s.so.1
#1  in _Unwind_Backtrace () from /lib64/libgcc_s.so.1
#2  in __GI___backtrace (array=<optimized out>, size=128) at ../sysdeps/x86_64/backtrace.c:109
#3  in my_print_stacktrace (stack_bottom=0x7f8df8a06e48 "", thread_stack=262144) at ./mysys/stacktrace.c:224
#4  in handle_fatal_signal (sig=11) at ./sql/signal_handler.cc:162
#5  <signal handler called>
#6  0x000000000166312c in ?? ()
#7  0x6574616765726700 in ?? ()
#8  0x0000000000002b21 in ?? ()
#9  0x2e20363100200064 in ?? ()
#10 0x0000000000000000 in ?? ()

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.052 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.