src-d / go-mysql-server

An extensible MySQL server implementation in Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Long processing queries don't stop if the connection is dead/killed until the timeout triggers

juanjux opened this issue · comments

Related to:
https://github.com/src-d/gitbase-spark-connector-enterprise/issues/81

If a connection is dead (for example because the client was killed) queries that take a long time to send anything back will continue happily running until the configured or OS timeout triggers, which could be a long time. We should be able to detect a dead connection and stop the running query.

This is a hairy problem because AFAIK we can't detect if a socket is dead without doing a test reading or writing from it, and that could interfere with the real readings/writings, specially if done on a goroutine as it probably should. Maybe reading and seeking one position back could work (but also could explode spectacularly).

The best option, if it worked, would be using a mysql.Conn.Ping() but if run from a goroutine it gives and error about reset counters (because the implementation really resets them so it looks like we can't call it in parallel with a running query.