Skip to content
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

Check connection liveness before sending query #882

Closed
methane opened this issue Oct 24, 2018 · 2 comments
Closed

Check connection liveness before sending query #882

methane opened this issue Oct 24, 2018 · 2 comments

Comments

@methane
Copy link
Member

methane commented Oct 24, 2018

ErrBadConn can be returned only when it's safe to retry. After sending query, we can't use it.

People must use DB.SetConnMaxLifetime to avoid connection closed from MySQL server, router, middlewares, to avoid such situation.

But we can save 90% cases by checking connection liveness before sending query.
Since Go 1.9, SyscallConn can be used to call system call directly. We can try non-blocking 1-byte read to detect connection closed by peer.

Ref: #657
Ref: golang/go#28607

@zplzpl
Copy link

zplzpl commented Nov 3, 2018

Is there any implementation example?

@methane
Copy link
Member Author

methane commented Nov 3, 2018

https://github.com/methane/peek?files=1
Here is, but only for Unix.

There are some drawbacks.
I'm not sure this is good idea. MySQL Connectors don't implement such checks.
All languages should keep connection fresh in pool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants