-
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
Go SQL client attempts write against broken connections #529
Comments
Try SetConnMaxLifetime(time.Minute)
|
@methane thank you for the super-fast response! I've put that into my code. I'm going to let it run for a bit, and let you know how it goes! |
@RobertGrantEllis any update? |
Apologies for the slow reply! I put this change in soon after the response from @methane, and intended to watch the production logs for a bit before closing this out. Apparently the latter fell by the wayside... Anyways-- I set the connection max lifetime to 30 minutes, and it appears to have resolved the issue, so thank you! I suspect that module-oriented fix could be to constantly read from each connection in the pool-- even in absence of an active query-- then, if an Pseudocode: for {
err = conn.Read(buffer)
if err != nil {
if err != io.EOF {
// report error
}
// lock ops mutex
// mark boolean as closed
conn.Close()
// release ops mutex
break
}
// report buffer back to whatever query activated the connection
// continue for iterations
} |
@RobertGrantEllis I agree that checking connection is closed or not before sending command is preferable. But (a) it requires dedicated reader goroutine, and (b) SetConnMaxLifetime() is far better than it. And even MySQL Connector/C (official implementation of client) doesn't try detecting broken connection before sending packet. dedicated reader goroutine.To check connection is closed by peer, Having dedicated two goroutines for read and write is common practice in Go. If performance overhead of dedicated reader goroutine is small enough, But my forecast is performance overhead is not negligible. SetConnMaxLifetime() is far better
But sometimes, TCP connections are broken silently. SetConnMaxLifetime() can solve almost clean TCP close ( SetConnMaxLifetime() has some nice side effects too (e.g. failover, load balancing, changing system variable by |
@methane thanks for the very detailed explanation. I do understand your points about why |
This commit fixes goharbor#4713, by adopting the suggested fix in: go-sql-driver/mysql#529 When creating the DB instance in orm, call `SetConnMaxLifetime()`
To clarify, what should the Go user do to mitigate errors arising from idle connections? Can go-sql-driver/mysql do a better job detecting dead/idle connections and respond appropriately, so that the database/sql abstraction can meet its commitments on automatic retry, reconnect? |
Stop multi posting. I replied on other issue. |
I closed this issue because #934 is the best we can do. |
Issue description
Intermittently I get failed writes against MariaDB. Lines like the below show up in my logs and data that was supposed to be written is lost. I have not yet tried writing retry logic in my application.
Both my Go app and MariaDB are running in Docker containers. However, I am seeing these errors when they on the same host, connecting over a local Docker network.
Docker version: 1.10.3
Example code
Error log
Configuration
Driver version (or git SHA):
Go version: run
go version
in your consoleServer version: E.g. MySQL 5.6, MariaDB 10.0.20
MariaDB: off-the-shelf container mariadb:10.1.19
Server OS: E.g. Debian 8.1 (Jessie), Windows 10
CoreOS 1122.3.0
The text was updated successfully, but these errors were encountered: