Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

KILL fails with err message "closed network connection" #635

Closed
carlosms opened this issue Mar 5, 2019 · 4 comments
Closed

KILL fails with err message "closed network connection" #635

carlosms opened this issue Mar 5, 2019 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@carlosms
Copy link
Contributor

carlosms commented Mar 5, 2019

Testing with v0.19.0-rc2.

$ go run cmd/srcd/main.go sql "SHOW PROCESSLIST"
+-----+------+---------------------+---------+---------+------+--------------------------------+--------------------------------+
| ID  | USER |        HOST         |   DB    | COMMAND | TIME |             STATE              |              INFO              |
+-----+------+---------------------+---------+---------+------+--------------------------------+--------------------------------+
|  49 | root | 192.168.160.2:43598 | gitbase | query   |  440 | SquashedTable(refs,            | /* Files named main.go in HEAD |
|     |      |                     |         |         |      | commit_files, files)(635/696)  | */                             |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                | SELECT f.repository_id,        |
|     |      |                     |         |         |      |                                | f.file_path,                   |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                |        LANGUAGE(f.file_path,   |
|     |      |                     |         |         |      |                                | f.blob_content) AS lang,       |
|     |      |                     |         |         |      |                                | f.blob_content,                |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                |        UAST(f.blob_content,    |
|     |      |                     |         |         |      |                                | LANGUAGE(f.file_path,          |
|     |      |                     |         |         |      |                                | f.blob_content)) AS uast       |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                | FROM   refs AS r               |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                |        NATURAL JOIN            |
|     |      |                     |         |         |      |                                | commit_files                   |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                |        NATURAL JOIN files AS f |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                | WHERE  r.ref_name = 'HEAD'     |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                |        AND f.file_path         |
|     |      |                     |         |         |      |                                | REGEXP('.*main.go')            |
|  87 | root | 192.168.160.2:43598 | gitbase | query   |  383 | SquashedTable(refs,            | /* Files named main.go in HEAD |
|     |      |                     |         |         |      | commit_files, files)(659/696)  | */                             |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                | SELECT f.repository_id,        |
|     |      |                     |         |         |      |                                | f.file_path,                   |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                |        LANGUAGE(f.file_path,   |
|     |      |                     |         |         |      |                                | f.blob_content) AS lang,       |
|     |      |                     |         |         |      |                                | f.blob_content,                |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                |        UAST(f.blob_content,    |
|     |      |                     |         |         |      |                                | LANGUAGE(f.file_path,          |
|     |      |                     |         |         |      |                                | f.blob_content)) AS uast       |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                | FROM   refs AS r               |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                |        NATURAL JOIN            |
|     |      |                     |         |         |      |                                | commit_files                   |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                |        NATURAL JOIN files AS f |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                | WHERE  r.ref_name = 'HEAD'     |
|     |      |                     |         |         |      |                                |                                |
|     |      |                     |         |         |      |                                |        AND f.file_path         |
|     |      |                     |         |         |      |                                | REGEXP('.*main.go')            |
| 268 | root | 192.168.160.2:43598 | gitbase | query   |    0 | running                        | SHOW PROCESSLIST               |
+-----+------+---------------------+---------+---------+------+--------------------------------+--------------------------------+

If I try to kill any of the queries it fails, and the queries keep running.

gitbase> KILL 49;
rpc error: code = Unknown desc = SQL query failed: invalid connection
gitbase> kill 87;
rpc error: code = Unknown desc = SQL query failed: invalid connection
gitbase> kill 123456;
rpc error: code = Unknown desc = SQL query failed: invalid connection

The logs are the same for existing and non-existing PID

time="2019-03-05T18:27:15Z" level=info msg="NewConnection: client 248"
time="2019-03-05T18:27:15Z" level=info msg="audit trail" action=authentication address="192.168.160.2:43606" success=true system=audit user=root
time="2019-03-05T18:27:15Z" level=info msg="kill connection: id 248, pid: 87"
time="2019-03-05T18:27:15Z" level=error msg="Conn 248: Flush() failed: write tcp 192.168.160.4:3306->192.168.160.2:43606: use of closed network connection"
time="2019-03-05T18:27:15Z" level=info msg="ConnectionClosed: client 248"
time="2019-03-05T18:27:24Z" level=info msg="NewConnection: client 249"
time="2019-03-05T18:27:24Z" level=info msg="audit trail" action=authentication address="192.168.160.2:43608" success=true system=audit user=root
time="2019-03-05T18:27:24Z" level=info msg="kill connection: id 249, pid: 123456"
time="2019-03-05T18:27:24Z" level=error msg="Conn 249: Flush() failed: write tcp 192.168.160.4:3306->192.168.160.2:43608: use of closed network connection"
time="2019-03-05T18:27:24Z" level=info msg="ConnectionClosed: client 249"
@ajnavarro
Copy link
Contributor

Did you execute KILL 1 before KILL 49? If yes, you closed your own connection, that's why the following queries will fail with invalid connection.

@carlosms
Copy link
Contributor Author

carlosms commented Mar 7, 2019

Testing with 2 mysql clients connecting to a gitbase 0.19.0 daemon:

Client A

MySQL [gitbase]> select connection_id();
+-----------------+
| connection_id() |
+-----------------+
|               4 |
+-----------------+
1 row in set (0.00 sec)

Client B


MySQL [gitbase]> select connection_id();
+-----------------+
| connection_id() |
+-----------------+
|               5 |
+-----------------+
1 row in set (0.01 sec)

MySQL [gitbase]> kill 4;
ERROR 2013 (HY000): Lost connection to MySQL server during query
MySQL [gitbase]> select connection_id();
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    6
Current database: gitbase

+-----------------+
| connection_id() |
+-----------------+
|               6 |
+-----------------+
1 row in set (0.00 sec)

Client A

MySQL [gitbase]> select connection_id();
+-----------------+
| connection_id() |
+-----------------+
|               4 |
+-----------------+
1 row in set (0.00 sec)

I also noticed another weird thing that might be related.
According to the mysql docs:

Thread processlist identifiers can be determined from the ID column of the INFORMATION_SCHEMA PROCESSLIST table, the Id column of SHOW PROCESSLIST output, and the PROCESSLIST_ID column of the Performance Schema threads table. The value for the current thread is returned by the CONNECTION_ID() function.

Which is true for a normal mysql server, connection_id and ID of show processlist match:

mysql> select connection_id();
+-----------------+
| connection_id() |
+-----------------+
|               8 |
+-----------------+
1 row in set (0.00 sec)

mysql> show processlist;
+----+-----------------+------------------+------+---------+------+------------------------+------------------+
| Id | User            | Host             | db   | Command | Time | State                  | Info             |
+----+-----------------+------------------+------+---------+------+------------------------+------------------+
|  4 | event_scheduler | localhost        | NULL | Daemon  |  262 | Waiting on empty queue | NULL             |
|  8 | root            | 172.17.0.3:40908 | NULL | Query   |    0 | starting               | show processlist |
|  9 | root            | 172.17.0.4:43044 | NULL | Sleep   |  192 |                        | NULL             |
+----+-----------------+------------------+------+---------+------+------------------------+------------------+
3 rows in set (0.01 sec)

But for a gitbase 0.19.0, the IDs do not match:

MySQL [gitbase]> select connection_id();
+-----------------+
| connection_id() |
+-----------------+
|               3 |
+-----------------+
1 row in set (0.00 sec)

MySQL [gitbase]> show processlist;
+------+------+------+------+---------+------+-------+------+
| Id   | User | Host | db   | Command | Time | State | Info |
+------+------+------+------+---------+------+-------+------+
|   12 | root | 172.17.0.1:58680 | gitbase | query   |    0 | running | show processlist |
+------+------+------+------+---------+------+-------+------+
1 row in set (0.00 sec)

MySQL [gitbase]> select connection_id();
+-----------------+
| connection_id() |
+-----------------+
|               3 |
+-----------------+
1 row in set (0.01 sec)

MySQL [gitbase]> show processlist;
+------+------+------+------+---------+------+-------+------+
| Id   | User | Host | db   | Command | Time | State | Info |
+------+------+------+------+---------+------+-------+------+
|   14 | root | 172.17.0.1:58680 | gitbase | query   |    0 | running | show processlist |
+------+------+------+------+---------+------+-------+------+
1 row in set (0.00 sec)

@kuba-- kuba-- self-assigned this Mar 11, 2019
@kuba--
Copy link
Contributor

kuba-- commented Mar 11, 2019

I you have a long running operations, e.g. PROCESLIST.ID = 123
then query:

KILL QUERY 123;

Works.

KILL 123 or KILL CONNECTION 123 just kills connection.

@kuba--
Copy link
Contributor

kuba-- commented Mar 11, 2019

It should work as follows:
KILL [CONNECTION | QUERY] processlist_id
kill query kills only query, otherwise connection will be closed. The connection assigned to the process list can be found in thread table which is missed.
In other words we should have mapping process_id -> connection_id. In KILL query we only pass process_id.

@kuba-- kuba-- transferred this issue from src-d/gitbase Mar 11, 2019
@kuba-- kuba-- added the bug Something isn't working label Mar 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants