Bug #58080 Crash on failure to create a thread to handle a user connection
Submitted: 9 Nov 2010 11:44 Modified: 15 Dec 2010 0:54
Reporter: Davi Arnaut (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S2 (Serious)
Version:5.5 OS:Any
Assigned to: Davi Arnaut CPU Architecture:Any
Tags: regression

[9 Nov 2010 11:44] Davi Arnaut
Description:
When the server fails to create a thread to handle a user connection, a error message is crafted using the ER() macro. The problem is that the macro relies on current_thd being available, that is, that the current thread has a THD object bound to it, which is not the case for the thread that accepts user connections.

How to repeat:
Make the mysql_thread_create in create_thread_to_handle_connection fail.

Suggested fix:
Use the ER_THD() macro instead of ER().
[9 Nov 2010 12:26] 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/123245

3105 Davi Arnaut	2010-11-09
      Bug#58080: Crash on failure to create a thread to handle a user connection
      
      The problem was that the scheduler function used to handle a
      new user connection could use the ER() macro without having a
      THD object bound to the current thread. The crash would happen
      whenever the function failed to create a new thread to handle a
      user connection. Thread creation can fail due to lack or limit
      of available resources.
      
      The solution is to simply use the ER_THD() macro instead and pass
      to it the THD object which would be bound to the connection.
     @ sql/mysqld.cc
        Use ER_THD and pass the object.
[9 Nov 2010 15:22] Dmitry Lenev
Approved with minor comment discussed on IRC.
[9 Nov 2010 15:59] 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/123305

3111 Davi Arnaut	2010-11-09
      Bug#58080: Crash on failure to create a thread to handle a user connection
      
      The problem was that the scheduler function used to handle a
      new user connection could use the ER() macro without having a
      THD object bound to the current thread. The crash would happen
      whenever the function failed to create a new thread to handle a
      user connection. Thread creation can fail due to lack or limit
      of available resources.
      
      The solution is to simply use the ER_THD() macro instead and pass
      to it the THD object which would be bound to the connection.
      
      Fix was tested manually. In a test case, it is too cumbersome to
      inject a error in this context.
     @ sql/mysqld.cc
        Use ER_THD and pass the object.
[13 Nov 2010 16:24] Bugs System
Pushed into mysql-trunk 5.6.99-m5 (revid:alexander.nozdrin@oracle.com-20101113155825-czmva9kg4n31anmu) (version source revid:alexander.nozdrin@oracle.com-20101113152450-2zzcm50e7i4j35v7) (merge vers: 5.6.1-m4) (pib:21)
[13 Nov 2010 16:33] Bugs System
Pushed into mysql-next-mr (revid:alexander.nozdrin@oracle.com-20101113160336-atmtmfb3mzm4pz4i) (version source revid:alexander.nozdrin@oracle.com-20101113152540-gxro4g0v29l27f5x) (pib:21)
[15 Dec 2010 0:54] Paul DuBois
Noted in 5.5.8 changelog.

Failure to create a thread to handle a user connection could result
in a server crash.
[16 Dec 2010 22:28] Bugs System
Pushed into mysql-5.5 5.5.9 (revid:jonathan.perkin@oracle.com-20101216101358-fyzr1epq95a3yett) (version source revid:jonathan.perkin@oracle.com-20101216101358-fyzr1epq95a3yett) (merge vers: 5.5.9) (pib:24)