Bug #11707 Network should be initialized after storage engine initialization
Submitted: 3 Jul 2005 7:20 Modified: 11 Oct 2005 23:22
Reporter: Domas Mituzas Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1, 5.0, 4.0 OS:Any (All)
Assigned to: Jim Winstead

[3 Jul 2005 7:20] Domas Mituzas
Description:
on MySQL server_init(), which includes bind() and listen() calls is issued before starting any other initializations, like storage handlers. This isn't an issue in MyISAM only databases, but as InnoDB initializations may take hours (with really big buffer pools and 1GB-sized transaction logs), this makes the server misbehave and deny incoming connections instead of rejecting/telling an error. 

How to repeat:
observe startup sequence. before applying the patch and after.

Suggested fix:
--- mysqld.cc	2005-06-11 04:30:36.000000000 +0300
+++ mysqld.cc.dmnew	2005-07-03 03:07:22.000000000 +0300
@@ -3115,7 +3115,6 @@
   mysql_data_home= mysql_data_home_buff;
   mysql_data_home[0]=FN_CURLIB;		// all paths are relative from here
   mysql_data_home[1]=0;
-  server_init();
 
   if (opt_bin_log && !server_id)
   {
@@ -3149,6 +3148,7 @@
   }
 #endif
 
+  server_init();
   /*
     init signals & alarm
     After this we can't quit by a simple unireg_abort
[3 Jul 2005 7:26] Domas Mituzas
diff in a file!

Attachment: startup-sequence.diff (application/octet-stream, text), 466 bytes.

[3 Jul 2005 12:36] Aleksey Kishkin
Domas, we read all tickets :-)
[28 Jul 2005 0:47] Jim Winstead
A possible problem is that server_init() also changes the uid of the server. We may need to just split out the listen() calls and do that after the storage engine initialization.
[28 Jul 2005 7:13] Domas Mituzas
why would setuid() matter? mysql is not using reserved ports, it shouldn't be an issue to bind, then?

on the other hand, accessing storage as root is really really bad issue then :)
[28 Jul 2005 17:18] Jim Winstead
The server already does call setuid() before accessing storage. The issue is that it does it in the middle of server_init() -- after opening the TCP/IP socket, but before opening the Unix domain socket.

I'll need to do some research to see if we have a good reason for opening the TCP/IP socket as root. Obviously it is not necessary for the default port of 3306.
[9 Aug 2005 2:07] 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/internals/28047
[23 Aug 2005 1:04] 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/internals/28665
[25 Aug 2005 18:23] Jim Winstead
Fixed in 5.0.13.
[13 Sep 2005 22:25] Mike Hillyer
Added to 5.0.13 changelog, noted in manual description for --port:

listitem>
        <para>
          Reorder network startup to come after all other initialization, particularly
          storage engine startup which can take a long time. This also prevents MySQL from
          being run on a privileged port (any port under 1024) unless run as the root user. (Bug #11707)
        </para>
      </listitem>
[11 Oct 2005 23:22] Jim Winstead
The patch was prepared against 4.1, but only pushed to the 5.0 tree.