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

go client reports invalid connection after idle for wait_timeout #327

Open
djshow832 opened this issue Jul 12, 2023 · 1 comment
Open

go client reports invalid connection after idle for wait_timeout #327

djshow832 opened this issue Jul 12, 2023 · 1 comment
Labels
wontfix This will not be worked on

Comments

@djshow832
Copy link
Collaborator

djshow832 commented Jul 12, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

dbt.mustExec("SET @@SESSION.wait_timeout = 2")

// wait for TiDB to close our connection
time.Sleep(3 * time.Second)

tx, err := dbt.db.Begin()
if err != nil {
	dbt.Fatal(err)
}

2. What did you expect to see? (Required)

The driver logs packets.go:122: closing bad idle connection: EOF 3 times but dbt.db.Begin doesn't report any errors because it creates a new connection internally and then retry.

3. What did you see instead (Required)

The driver logs packets.go:37: unexpected EOF and dbt.db.Begin reports invalid connection.

4. What is your version? (Required)

master.

The reason:
TiProxy doesn't close the connection immediately after wait_timeout and still receives requests. After it receives the request, it finds that TiDB has disconnected and then closes the client connection. So the client encounters an ErrInvalidConn in readPacket instead of ErrBadConn in writePacket.
The client will retry by creating a new connection if encounters ErrBadConn but won't retry if encounters ErrInvalidConn, see https://github.com/golang/go/blob/master/src/database/sql/sql.go#L1536-1546
I think there's no way to solve it.

@djshow832 djshow832 changed the title go client reports error after idle for wait_timeout go client reports invalid connection after idle for wait_timeout Jul 12, 2023
@djshow832
Copy link
Collaborator Author

Maybe a workaround is to add a client idle timeout to tiproxy configuration, like client timeout in haproxy: https://www.papertrail.com/solution/tips/haproxy-logging-how-to-tune-timeouts-for-performance/

@djshow832 djshow832 added the wontfix This will not be worked on label Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant