0

I'm currently working with a mysql connection in my vs 2017 project and I need to check if the wait_timeout exceeded. Unfortunately the state of the connection still shows open after the timeout. Is there a way to check that without try catch (try catch doesnt catch the thrown exception in my case)?

2
  • what do you want to check? Commented Jun 10, 2020 at 9:09
  • I need to check if the wait_timeout exceeded Commented Jun 10, 2020 at 10:59

1 Answer 1

2

When the wait_timeout is exceeded, the MySQL Server simply closes the connection. No notification that this has happened is "pushed" to the client, so the connection state won't change; this can only be detected by trying to read from the underlying TCP socket. (For a deep technical writeup on this, see https://github.blog/2020-05-20-three-bugs-in-the-go-mysql-driver/.) Any subsequent use of that connection will typically throw an exception.

There is a way to test the connection without throwing an exception: call MySqlConnection.Ping; if the connection is closed it will return false.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, sadly MySqlConnection.Ping throws this exception in my case "System.Net.Sockets.SocketException: 'An established connection was aborted by the software in your host machine'"
That's only because you're breaking on exceptions in the debugger; see stackoverflow.com/questions/62302876/…. The exception shouldn't be thrown from Ping in regular usage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.