Skip to content

backend, net: close the client connection when the backend is down #198

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

Merged
merged 2 commits into from
Jan 19, 2023

Conversation

djshow832
Copy link
Collaborator

@djshow832 djshow832 commented Jan 18, 2023

What problem does this PR solve?

Issue Number: close #195

Problem Summary:
On the serverless tier, when the client is idle for 5 minutes, the backend will quit. But the TiProxy doesn't know the backend quits because it's still reading the client. Then, the serverless tier thinks the connection is still alive and then wakes up a new TiDB instance.

So, TiProxy should always detect the backend and disconnect the client when the backend quits.

What is changed and how it works:

  • Add a ticker on BackendConnMgr to check the backend periodically in the background goroutine
  • Wrap the PacketIO.conn with a buffer and add PacketIO.IsPeerActive()
  • Update the parameters of NewBackendConnMgr to make them configurable in the tests
  • Fix checkConnClosed4Proxy. It never worked before because ts.mp.err is not checked

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code
  1. Start a MySQL client to connect to TiProxy
  2. Kill the TiDB
  3. The TiProxy shows that the client connection is closed within 1 minute
[2023/01/18 19:17:37.985 +08:00] [INFO] [main.nsmgr.router] [router/router_score.go:302] [update backend] [namespace=default] [addr=127.0.0.1:4000] [prev_status=healthy] [cur_status=down]
[2023/01/18 19:18:20.330 +08:00] [INFO] [main.proxy.conn.be] [backend/backend_conn_mgr.go:532] [backend connection is closed, close client connection] [connID=0] [remoteAddr=127.0.0.1:57965] [client=127.0.0.1:57965] [backend=127.0.0.1:4000]
[2023/01/18 19:18:20.331 +08:00] [INFO] [main.proxy] [proxy/proxy.go:166] [connection closed] [connID=0] [remoteAddr=127.0.0.1:57965]

Notable changes

  • Has configuration change
  • Has HTTP API interfaces change (Don't forget to add the declarative for API)
  • Has tiproxyctl change
  • Other user behavior changes

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@djshow832 djshow832 requested a review from xhebox January 18, 2023 11:13
@xhebox xhebox merged commit d6e1f92 into pingcap:main Jan 19, 2023
@djshow832 djshow832 deleted the disconnect_client branch January 19, 2023 08:16
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

Successfully merging this pull request may close these issues.

Disconnect the client if the backend quits
2 participants