Bug #31745 mysqld crash handler does not work on windows
Submitted: 22 Oct 2007 10:14 Modified: 25 Feb 2008 19:31
Reporter: Magnus Blåudd Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S2 (Serious)
Version:5.0.* OS:Windows
Assigned to: Vladislav Vaintroub CPU Architecture:Any
Tags: unscheduled

[22 Oct 2007 10:14] Magnus Blåudd
Description:
While working on BUG#18441 I found that each thread in mysqld will install an empty signal handler. This has the effect that a SIGSEGV in for example 'mysql_update' will more or less be ignored. It will close the connection to the client causing the segfault, but when returning from the signal handler the thread will start to execute 'main' thus starting a new mysqld(in the signal handler thread).

Have rewritten the signal handling code for windows in order to avoid this problem  - see the attached patch.

All threads will have a "handle_win_signal" installed as signal handler for all the signals to catch. That function will:
- in case of SIGINT do a "ordered shutdown" by signaling the shutdown thread which will 'kill_server' 
- in all other case it will call the 'handle_segfault' function (which need to be moved out of the #ifdef that exposes it only on some systems). This will give us the same behavior as on Linux ie. an error log file will be generated indicating which signal was caught, the time it occurred, special settings used and so on.

How to repeat:
Add code that uses a NULL pointer to 'mysql_update'

$ bk diffs -u
===== sql_update.cc 1.222 vs edited =====
--- 1.222/sql/sql_update.cc     2007-07-31 13:42:53 +02:00
+++ edited/sql_update.cc        2007-10-22 12:13:26 +02:00
@@ -134,6 +134,10 @@
   SELECT_LEX    *select_lex= &thd->lex->select_lex;
   bool need_reopen;
   List<Item> all_fields;
+
+  char* p= 0;
+  *p= 1;
+
   DBUG_ENTER("mysql_update");

Then run a SQL query like "UPDATE t1 set a=a" and watch the behaviour.
 
   LINT_INIT(timestamp_query_id);

Suggested fix:
All threads will have a "handle_win_signal" installed as signal handler for all the signals to catch. That function will:
- in case of SIGINT do a "ordered shutdown" by signaling the shutdown thread which will 'kill_server' 
- in all other case it will call the 'handle_segfault' function (which need to be moved out of the #ifdef that exposes it only on some systems). This will give us the same behavior as on Linux ie. an error log file will be generated indicating which signal was caught, the time it occurred, special settings used and so on.
[22 Oct 2007 13:11] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/36036

ChangeSet@1.2530, 2007-10-22 15:10:06+02:00, msvensson@shellback.(none) +3 -0
  Bug#31745 mysqld crash handler does not work on windows
  - Rework signal handler code to either shutdown using the shutdown
    thread or call 'handle_segfault' to print out crash info and then
    crash the mysqld
[18 Feb 2008 9:52] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/42471

ChangeSet@1.2568, 2008-02-18 10:51:24+01:00, vvaintroub@wva. +5 -0
  Bug#31745 - crash handler does not work on Windows
  - Replace per-thread signal()'s with  SetUnhandledExceptionFilter(). 
    The only remaining signal() is for SIGABRT (default abort()
    handler in VS2005 is broken, i.e removes user exception filter)
  - remove MessageBox()'es  from error handling code
  - Windows port for print_stacktrace() and write_core()
[19 Feb 2008 11:38] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/42540

ChangeSet@1.2568, 2008-02-19 12:37:39+01:00, vvaintroub@wva. +5 -0
  Bug#31745 - crash handler does not work on Windows
  - Replace per-thread signal()'s with  SetUnhandledExceptionFilter(). 
    The only remaining signal() is for SIGABRT (default abort()
    handler in VS2005 is broken, i.e removes user exception filter)
  - remove MessageBox()'es  from error handling code
  - Windows port for print_stacktrace() and write_core() 
  - Cleanup, removed some unused functions
[20 Feb 2008 23:47] Vladislav Vaintroub
approved by email
[25 Feb 2008 15:59] Bugs System
Pushed into 5.1.24-rc
[25 Feb 2008 16:05] Bugs System
Pushed into 5.0.58
[25 Feb 2008 16:05] Bugs System
Pushed into 6.0.5-alpha
[25 Feb 2008 19:31] Paul DuBois
Noted in 5.0.58, 5.1.24, 6.0.5 changelogs.

The mysqld crash handler failed on Windows.
[26 Feb 2008 0:34] Iggy Galarza
Marked Bug#29385 as a duplicate.