-
Notifications
You must be signed in to change notification settings - Fork 62
fix leaking connections when user client closes connection #222
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
Conversation
Signed-off-by: Teo Koon Peng <[email protected]>
…ctions Signed-off-by: Teo Koon Peng <[email protected]>
Signed-off-by: Teo Koon Peng <[email protected]>
Signed-off-by: Teo Koon Peng <[email protected]>
// A permanent error suggests the request should be aborted. | ||
log.Printf("[%s] %s", *resp.Id, err) | ||
log.Printf("[%s] Closing backend connection", *resp.Id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please only log a single line:
log.Printf("[%s] Relay error: %v, closing backend connection", *resp.Id, err)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in 301b04d
Thanks for moving the PR, the CI looks happy now. Will you also address the other comments from #220? |
Signed-off-by: Teo Koon Peng <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
It causes the postsubmit integration test to fail with: ``` error: Timeout occurred TEST FAILED: echo command did not run, output was "", want "hello" ``` when testing `kubectl exec`. https://source.cloud.google.com/results/invocations/8f0b86f7-c5c4-41a3-9e4c-43e325d9e1ae/targets/%2F%2Fsrc%2Fgo%2Ftests:relay_test/log - Revert "Use %v instead of %s in relay logs (#224)" - Revert "fix leaking connections when user client closes connection (#222)"
Re-reverting #222 with a fix to relay_test.sh from the postsubmit test. The problem is mistakenly using `w.Write` at server.go:260, the response writer is no longer valid after the connection has been hijacked, we need to use `bufrw.Write` instead. --------- Signed-off-by: Teo Koon Peng <[email protected]>
Same as #220, but ported to this repo.
When the user client closes the connection, it is not propagated to the backend. For simple "one shot" requests, there is no huge impact as the response would just be dropped, however for long running requests (chunked encoding or websockets), the backend doesn't know that the user client has closed the connection and it keeps sending new updates to the relay client, which also doesn't know and so keep forwarding that to the relay server.
The fix applied is:
StopRelayRequest
to the broker to "forget" a relaying request. This will cause the relay server to response with a permanent error the next time the relay client tries to send a response for that id. This will in turn cause the relay client to close the connection to the backend.backoff.Permanent
, resulting in the check to always fail and never handling it.