Bug #93240 wait_timeout error not clear and not sent to client before closing connection
Submitted: 17 Nov 2018 21:34 Modified: 1 Apr 2019 18:01
Reporter: Mattias Jonsson (OCA) Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: Connection Handling Severity:S4 (Feature request)
Version:5.7.24, 8.0.13 OS:Linux
Assigned to: CPU Architecture:Any
Tags: Contribution

[17 Nov 2018 21:34] Mattias Jonsson
If clients are not using the connection within wait_timeout, then they will be closed by the server and the server can write a non-clear error message to the error log:
[Note] Aborted connection <connection_id> to db: '<db>' user: '<user>' host: '<host>' (Got timeout reading communication packets)

Which also is the same as if there is an error due to net_read_timeout.

And the client is not informed of the reason for the closed connection, it typically sees:
2013: 'Lost connection to MySQL server during query'
2006: 'MySQL server has gone away'

These are very generic errors and does not give a clear hint that the connection was closed by the server due to wait_timeout.

How to repeat:
Read wait_timeout.test or simply:
SET @@session.wait_timeout = 2;
# Wait 3 seconds

Suggested fix:
I suggest that 'wait_timeout' is mentioned in the server error log as a separate error if it triggered the aborted connection and that it is propagated to the client before the server closes the connection, so the client can detect the reason for the closed connection. Also update the client code to read/check for errors if there was a write error.

This could be seen as a fix for:
Bug #24903	timeout in mysqld.conf causes Got timeout reading communication packets
Bug #75082	would like easy way to distinguish between KILL CONNECTION and a server restart
Bug #83843	Error message "MySQL server has gone away" sofistication, for the 'wait_timeout' (3) scenario.

Not sure if this bug would also be affected:
Bug #90753	Wait_timeout exceeded message not triggered
[18 Nov 2018 5:46] MySQL Verification Team
Hello Mattias,

Thank you for the feature request!

[20 Nov 2018 12:39] MySQL Verification Team
Hello Mattias,

As you probably know that in order to submit contributions you must first sign the Oracle Contribution Agreement (OCA). For additional information please check http://www.oracle.com/technetwork/community/oca-486395.html.
If you have any questions, please contact the MySQL community team at https://dev.mysql.com/community/

[6 Dec 2018 15:26] Mattias Jonsson
Pull request from https://github.com/mysql/mysql-server/pull/233

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: bug93240.patch (application/octet-stream, text), 15.53 KiB.

[7 Dec 2018 5:02] MySQL Verification Team
Thank you Mattias for the contribution.

[12 Dec 2018 15:22] OCA Admin
Contribution submitted via Github - Bug#93240 wait_timeout error not clear and not sent to client. 
(*) Contribution by Mattias Jonsson (Github mjonss, mysql-server/pull/233#issuecomment-446191639): > Hi, thank you for submitting this pull request. In order to consider your code we need you to sign the Oracle Contribution Agreement (OCA). Please review the details and follow the instructions at http://www.oracle.com/technetwork/community/oca-486395.html
> Please make sure to include your MySQL bug system user (email) in the returned form.
> Thanks

I am included in the booking.com OCA, also states ''(OCA)'' after my name (as reporter) in the bug: https://bugs.mysql.com/bug.php?id=93240

Contribution: git_patch_236567060.txt (text/plain), 15.97 KiB.

[1 Apr 2019 18:01] Paul DuBois
Posted by developer:
Fixed in 8.0.17.

When clients were terminated for inactivity exceeding the
wait_timeout value, the message written to the error log was unclear.
Now ER_NET_WAIT_ERROR is written, which is more specific about the
cause of the problem.
[8 Aug 2019 15:29] Paul DuBois
Posted by developer:
Thanks to Mattias Jonsson for the contribution.