-
Notifications
You must be signed in to change notification settings - Fork 544
watch: prevent done callback from being called twice on connection loss #2389
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
watch: prevent done callback from being called twice on connection loss #2389
Conversation
Avoids multiple invocations of the done callback when a watch connection is closed unexpectedly (e.g., a premature socket close). The fix sets doneCalled = true before calling controller.abort(), to ensure that any AbortError triggered by aborting does not result in another call to the done callback. A regression test is included to simulate an abrupt connection termination. It uses a real HTTP server that flushes headers and then destroys the connection immediately. This reliably triggers the combination of AbortError and Premature close needed to reproduce the issue. Refs: kubernetes-client#2387
Welcome @bverhoeven! |
The changes LGTM. I'll give the other maintainers a chance to weigh in on the test since it's different from what we normally do (binding a port instead of using nock). Personally, I'm good with it since nock has been giving us issues lately particularly around these types of error edge cases. |
Thanks! Yeah, I spent quite a bit of time trying to get this working with nock, but couldn’t get it to reliably simulate an abrupt disconnect. As mentioned in this comment, this setup seemed like the most dependable way to reproduce the issue. Happy to adjust if maintainers prefer a different approach, but I figured it was worth using something that reliably triggers the edge case. |
This looks good to me thanks for adding the test. /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brendandburns, bverhoeven The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Avoids multiple invocations of the done callback when a watch connection is closed unexpectedly (e.g., a premature socket close). The fix sets
doneCalled = true
before callingcontroller.abort()
, to ensure that anyAbortError
triggered by aborting does not result in another call to the done callback.A regression test is included to simulate an abrupt connection termination. It uses a real HTTP server that flushes headers and then destroys the connection immediately. This reliably triggers the combination of
AbortError
and "Premature close" needed to reproduce the issue.Refs: #2387