Bug #60781 Shutting down mysql proxy does not remove listening socket
Submitted: 6 Apr 2011 15:31 Modified: 14 Jun 2012 18:56
Reporter: Jacek Osiecki Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Proxy: Core Severity:S2 (Serious)
Version:0.8.1 OS:Linux
Assigned to: CPU Architecture:Any
Tags: listening on socket, proxy, shutdown

[6 Apr 2011 15:31] Jacek Osiecki
Description:
If mysql-proxy is configured to listen on a unix socket, using directive:

proxy-address = /path/to/socket/mysql.sock

then, after shutting down mysql-proxy does not remove that socket.
During next startup, mysql-proxy fails to start, reporting in log file:

(critical) network-socket.c:401: bind(/path/to/socket/mysql.sock) failed: Address already in use (98)

This happens until socket file is manually removed.

How to repeat:
Just add another frontend, defining a path to unix socket:

proxy-address = /path/to/socket/mysql.sock

and try to restart mysql-proxy. It will correctly shut down, and won't start again.

Suggested fix:
1. if mysql-proxy has created a unix proxy during startup, it should remove it during shutdown
2. even if socket exists, mysql-proxy should check if it is still functioning - if not, socket should be removed first
3. mysql-proxy does not report failure during startup - shouldn't it wait and check if all frontends has been started successfully? Current behaviour makes it quite hard to maintain - administrator does not know instantly that service actually did not start.
4. Another thing: even if it is not possible to start a frontend (socket exists, or port is already in use), should mysql-proxy shut down if there are more frontends defined and some CAN be set up? Could it be configurable?
[5 May 2011 19:58] Sveta Smirnova
Thank you for the report.

I can not repeat described behavior. How do you shut down MySQL Proxy?
[6 May 2011 9:27] Jacek Osiecki
Hi Sveta,

Since there is no standard procedure of stopping mysql-proxy (like mysqladmin shutdown for the mysql server), my scripts are simply killing the mysql-proxy process.

By saying that you can't repeat this behaviour, do you mean that:
 a) mysql-proxy after being killed removes the unix socket
 b) mysql-proxy starts even when the socket exists?

Actually (b) is much more important, since this might prevent mysql-proxy from starting after unexpected system crash due to ex. power failure...
[11 May 2011 11:32] Sveta Smirnova
Thank you for the feedback.

>  a) mysql-proxy after being killed removes the unix socket

Yes, mysql-proxy removes socket after killing, but I use kill [mysql-proxy-id], not kill -9 or so. Which signal do you use?
[11 Jun 2011 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[13 Jun 2012 8:20] milo bodewes
On a debian system using version 8.0 this behavoir is shown using the default init script.
I tried sending custom signals (9) but to no effect. It doesn't delete the socket.

I also noticed it sets permissions to 755 and user root (running as mysql) disallowing other users access.
[13 Jun 2012 8:28] Jacek Osiecki
For me, it's still an error that mysql_proxy crashes if socket exists - even though the process does not.
Proxy should check if the socket is still alive and if not - replace it with new, proper one.
[13 Jun 2012 8:31] milo bodewes
Bit more info
Config file used:

[mysql-proxy]
proxy-address=/var/run/mysqld/mysqld.sock
log-file=/var/log/mysql/mysql_proxy.log
log-level=debug
user=mysql
proxy-backend-addresses=127.0.0.1:3307
proxy-read-only-backend-addresses = 10.0.101.11:3306
[13 Jun 2012 8:34] milo bodewes
Jacek Osiecki: agreed. 
I also think it should respect the "run as user setting" and set proper permisssions.
[14 Jun 2012 18:56] Sveta Smirnova
Thank you for the report.

> On a debian system using version 8.0 this behavoir is shown using the default init script.

What do you mean by behavior shown by default init script? kill <MYSQL_PROXY_PID> removes socket, kill - 9 does not.

I can verify the fact mysql-proxy does not start if old unused socket exists, although other MySQL products, such as server, do it. This should be fixed.
[18 Dec 2013 17:27] Paul DuBois
Noted in 0.8.4 changelog.

If MySQL Proxy was configured to listen on a Unix socket file, it
failed to remove the file when exiting, causing the next Proxy
instance to fail at startup.