Bug #80234 Client library fails to close handle on mutex used by shared memory connections
Submitted: 2 Feb 2016 11:58 Modified: 15 Feb 2016 17:42
Reporter: Daniel Blanchard Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S2 (Serious)
Version:5.7 OS:Any
Assigned to: CPU Architecture:Any

[2 Feb 2016 11:58] Daniel Blanchard
Description:
The Windows client library opens a handle on a mutex for shared memory connections but does not explicitly close it.

An attempt to restart the MySQL server (configured to use shared memory connections) will fail if a client process still has a handle open on the shared memory mutex as the server will fail to (re)create the mutex.

How to repeat:
1) Start MySQL server with shared memory connections enabled.
2) Connect to the server using a shared memory connection - e.g. use 
mysql.exe --protocol=memory -u root
3) Shut the server down whilst leaving the client running
4) Attempt to start the server again: Startup of server fails with error "Can't create shared memory service: Another instance of application already running.. : No such file or directory"

Suggested fix:
Call CloseHandle(connect_named_mutex) and set connect_named_mutex = NULL in the create_shared_memory function in sql-common\client.c after the ReleaseMutex(connect_named_mutex) call and in the err: code block.
[15 Feb 2016 17:42] Paul DuBois
Noted in 5.7.12, 5.8.0 changelogs.

For shared-memory connections on Windows, the client library opened a
handle on a mutex but did not close it. Subsequent attempts to
restart the server on the other end of the connection failed if the
client still had the mutex handle open.