-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
packets.go:36: unexpected EOF (Invalid Connection) #674
Comments
The way to solve is :- |
There is a typo in your solution maybe version difference... https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns so I used |
@heisGarvit - fixed |
Also running into this, seems strange that the generally accepted solution everywhere is to "disable idle connections". Was the root cause for this discovered? Are there plans to fix it so that idle connections work as intended? |
General solution is
Root cause is TCP and request-response protocol. HTTP keep-alive has same problem. For example, AWS's ELB (load balancer, which is "client" to application) has 60sec keep-alive. |
Even if server's wait_timeout is long enough, router or OS may close long idle connection |
Hi, |
Fixes invalid connection errors according to go-sql-driver/mysql#674
Another way to solve this is to set the tcp keep alive on the connection:
|
TCP Keep-Alive solves only very limited cause of this issue. |
Something to do with how golangs sql library functions. go-sql-driver/mysql#674 for reference.
Wait, so what is the right way for us to use database/sql in Go applications? Vivid Cortex says to trust the lib to manage all retry, reconnect, connection pooling, timeout logic. https://www.vividcortex.com/blog/2015/09/22/common-pitfalls-go/ But in practice a default SQL client configuration fails to reconnect to the database after several hours of inactivity. Should the user set |
You didn't read my comments on various places? Use SetConnMaxLifetime().
He didn't say default configuration. You must use DB.SetConnMaxLifetime to use "e all retry, reconnect, connection pooling, timeout logic."
Have you read my comments before bloat posting?? I never recommended such settings. |
We recently ran into a similar issue, frequently seeing |
@methane Why not In my understanding, set I just noticed that |
It's up to your application. In application using hundreds queries/sec, even only 1 second reduce connection overhead less than 1/100. But 1sec may be too defensive for most cases. 1~3 minutes may be better in general.
SetConnMaxIdleTime solves only one problem (someone closes long idle TCP connection).
You can imagine many scenarios that forever reused connections make trouble. Limiting max lifetime is the best practice to keep your whole system healthy. That's why I recommend SetConnMaxLifetime even for Go 1.15+. SetConnMaxLifetime is useful only when you really need to set different timeout for lifetime and idletime. But it's very rare. Setting only SetConnMaxLifetime is enough for 99.99% users. |
As a supplement, when I set
|
In particular, the mysql driver has an issue where it closes the connection if using TCP and gets an invalid connection error. The error is "unexpected EOF", and can be work around by setting the number of idle connections to 0. SetMaxIdleConns(0). But updating the driver should also fix the bug. go-sql-driver/mysql#674
Issue description
Getting Invalid Connection issues.
Error log
Go version: run
go version
in your console=> go1.9 linux/386
Server version: E.g. MySQL 5.6, MariaDB 10.0.20
=> 5.5.56-MariaDB
Server OS: E.g. Debian 8.1 (Jessie), Windows 10
=> Centos
The text was updated successfully, but these errors were encountered: