sql-proxy icon indicating copy to clipboard operation
sql-proxy copied to clipboard

Re-connect to server-proxy if remote connection is closed.

Open fatih opened this issue 4 years ago • 0 comments

We should handle the edge cases for remote connections being closed. The client (sql-client-proxy) might lose the connection to sql-server-proxy due to the connection being closed via the database. If that happens, the client might assume that the TCP connection is still in-tact, but any writes on the TCP connection will fail.

If sql-server-proxy loses the connection to the database, it'll print this error:

2021/01/19 14:56:04 instance remote conn closed connection

If sql-client-proxy loses the connection to the sql-server-proxy, it'll print this error:

2021/01/19 14:56:04 instance remote connection closed connection

Finally, the MySQL client, in our example the mysql CLI will print this error when we try to send any commands (a.k.a write to the TCP connection):

mysql> \s
ERROR 2013 (HY000): Lost connection to MySQL server during query

However, the MySQL client is smart enough to retry and make a new connection:

mysql> \s
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    119159
Current database: *** NONE ***

--------------
mysql  Ver 14.14 Distrib 5.7.32, for osx10.16 (x86_64) using  EditLine wrapper

Connection id:          119159
Current database:
Current user:           vt_app@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.7.9-Vitess MySQL Community Server - GPL
Protocol version:       10
Connection:             127.0.0.1 via TCP/IP
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
TCP port:               3307
--------------

fatih avatar Jan 19 '21 12:01 fatih