Bug #37629 mysqld starts two instances with same socket without error message
Submitted: 25 Jun 2008 12:56 Modified: 24 Feb 2015 6:10
Reporter: Susanne Ebrecht Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.0, 5.1 OS:Linux
Assigned to: CPU Architecture:Any

[25 Jun 2008 12:56] Susanne Ebrecht
Description:
On same environment but complete independent instances:

080625 14:22:01 [Note] ./libexec/mysqld: ready for connections.
Version: '5.0.66-debug'  socket: '/tmp/mysql50bzr.sock'  port: 6850  Source distribution

080625 14:21:31 [Note] ./libexec/mysqld: ready for connections.
Version: '5.0.66'  socket: '/tmp/mysql50bzr.sock'  port: 6858  Source distribution

As you can see, two deamons are started using the same socket but different ports.

$ ps ax | grep mysql
12607 pts/5    Sl     0:00 ./libexec/mysqld --defaults-file=/home/miracee/mysql50test/etc/my.cnf

12633 pts/4    Sl     0:00 ./libexec/mysqld --defaults-file=/home/miracee/mysql50bzr/etc/my.cnf

I know, my error here was, that I copied my.cnf from one system to the other and then changed port on the second but I forgot to change socket there.

You can also work on these two systems and all will get stored at the right data dir but it will get confusion when you make at one instance directory:

$ ./bin/mysqladmin shutdown

Then it will shutdown the wrong instance.

I remember that there was an error message at the past, when you tried to start a second deamon with same socket. 

Where is it gone?

Why is it possible to start a second daemon without getting an error message or a note that socket already is in use?

How to repeat:
Get fresh mysql 5.0 bzr tree.

Make two directories:

$ mkdir mysql-5.0-src1
$ mkdir mysql-5.0-src2

copy mysql source into these two directories.

$ cp BZR_TREE mysql-5.0-src1/
$ cp BZR_TREE mysql-5.0-src2/

$ cd mysql-5.0-src1

$ ./BUILD/compile-amd64-debug-max --prefix=/home/yourhome/mysql-test-1 -c
$ make
$ make install

$ cd ../mysql-5.0-src2

$ ./BUILD/compile-amd64-debug-max --prefix=/home/yourhome/mysql-test-2 -c
$ make
$ make install

$ cd /home/yourhome/mysql-test-1
$ ./bin/mysql_install_db
$ mkdir etc
$ cd etc
$ vi my.cnf

Here is the my.cnf

[mysqld]
port = 6850
socket = /tmp/mysql50bzr.sock
[client]
port = 6850
socket = /tmp/mysql50bzr.sock

$ cd /home/yourhome/mysql-test-2
$ ./bin/mysql_install_db
$ mkdir etc
$ cd etc
$ vi my.cnf

Here is the my.cnf

[mysqld]
port = 6858
socket = /tmp/mysql50bzr.sock
[client]
port = 6858
socket = /tmp/mysql50bzr.sock

$ cd /home/yourhome/mysql-test-1
$ ./libexec/mysqld --defaults-file=/home/yourhome/mysql-test-1/etc/my.cnf &

080625 14:22:01 [Note] ./libexec/mysqld: ready for connections.
Version: '5.0.66-debug'  socket: '/tmp/mysql50bzr.sock'  port: 6850  Source distribution

Best to use another shell now:
$ cd /home/yourhome/mysql-test-2
$ ./libexec/mysqld --defaults-file=/home/yourhome/mysql-test-2/etc/my.cnf &

80625 14:21:31 [Note] ./libexec/mysqld: ready for connections.
Version: '5.0.66'  socket: '/tmp/mysql50bzr.sock'  port: 6858  Source distribution

$ ps ax | grep mysql
you will see two processes

$ cd /home/yourhome/mysql-test-2
$ ./bin/mysqladmin shutdown

$ ps ax | grep mysql

here it seems randomly which daemon will stay and which was shutted down.
Sometimes the right daemon got the shutdown. 
But also often the other daemon got it.

If you have luck and the right daemon got the shutdown just start it again and try to shutdown the other.

Suggested fix:
Check if socket is already in use and if it is then just give out an error message and don't start the daemon a second time on same socket.
[24 Feb 2015 6:10] Erlend Dahl
Fixed in 5.7.5 under the heading of 17286856:

[25 Sep 2014 10:52] Paul Dubois

Noted in 5.7.5 changelog.

A server could have its socket file taken over by a second server
listening on different TCP/IP port but the same socket file. The
socket file also would be unlinked by normal shutdown of the second
server. To avoid this, the server now uses a lock file with the same
name as the socket file and a .lock suffix. (For example,
/tmp/mysql.sock has a lock file of /tmp/mysql.sock.lock.) The lock
file contains the process ID of the server process that created the
socket file.