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

Cancel outstanding requests when destroying conns #355

Merged
merged 6 commits into from
Oct 27, 2023

Conversation

DMRobertson
Copy link
Contributor

Will help with #294.

@DMRobertson DMRobertson marked this pull request as ready for review October 26, 2023 15:30
Comment on lines 82 to 84
if response.duration > cancelWithin {
t.Errorf("Waited for %s, but expected second sync to cancel after at most %s", response.duration, cancelWithin)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my attempt to detect if the request was cancelled early.

I did wonder about explicitly making a request with client-created context. But I wasn't sure if http.Client would mark the context as Done when the request ends.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I wasn't sure if http.Client would mark the context as Done when the request ends.

seemingly not. That makes the test much cleaner.

@@ -723,6 +724,8 @@ func (s *ConnState) trackProcessDuration(ctx context.Context, dur time.Duration,
// Called when the connection is torn down
func (s *ConnState) Destroy() {
s.userCache.Unsubscribe(s.userCacheID)
logger.Debug().Str("user_id", s.userID).Str("device_id", s.deviceID).Msg("cancelling any in-flight requests")
s.cancelLatestReq()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nil check?

Grr. Is there no tooling for this?
@DMRobertson DMRobertson merged commit 759146e into main Oct 27, 2023
7 checks passed
@DMRobertson DMRobertson deleted the dmr/cancel-ctx-on-conn-shutdown branch October 27, 2023 15:22
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.

2 participants