Bug #33137 implement proper error checking for Winsock functions
Submitted: 11 Dec 2007 13:11 Modified: 11 Dec 2007 14:02
Reporter: Axel Schwenke Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: C API (client library) Severity:S4 (Feature request)
Version:5.0.30 OS:Windows (5.2.3790 (2003 Server))
Assigned to: CPU Architecture:Any

[11 Dec 2007 13:11] Axel Schwenke
When the bind() call (in sql/mysqld.cc:network_init()) on the INET socket fails, mysqld reports an error like that:

Can't start server: Bind on TCP/IP port: No such file or directory
[ERROR] Do you already have another mysqld server running on port: 3310 ?
[ERROR] Aborting

Observation 1: the error message looks bogus. ENOENT is a strange error code for failed bind() on an INET socket.

Observation 2: in Microsofts documentation on bind() (http://msdn2.microsoft.com/en-us/library/ms737550.aspx) there is no reference to errno being set in case of failure. Instead one should use WSAGetLastError() to get the latest error from a Winsock operation.

How to repeat:
Make MySQL startup fail, i.e. by forcing it to use an already used TCP port. Then check if you get the proper error message (something like "port already in use").

Suggested fix:
When compiling for Windows, failed calls to Winsock functions should use WSAGetLastError() to get a proper error code. There are probably a lot more places than just the bind() in sql/mysqld.cc:network_init()
[11 Dec 2007 13:38] Axel Schwenke
Tried to reproduce on Win2000 but don't get the "Can't start server: Bind on TCP/IP port" message at all.
[11 Dec 2007 14:02] Axel Schwenke
Seems to be closely related to bug#28775