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

Context & Response #114

Merged
merged 4 commits into from
Dec 9, 2024
Merged

Context & Response #114

merged 4 commits into from
Dec 9, 2024

Conversation

akarl
Copy link
Collaborator

@akarl akarl commented Dec 6, 2024

  • Uses proper context deadline and cancellation so that a context cancel will stop stop waiting for responses.
  • Simplifies response handling by using context.Done() and merging error and response chan on the request.
  • Fixes a bug where a connection or channel would close before monitorAndWait was properly setup.

This fixes an issue where the connection or channel would be closed
before NotifyClose is setup. That can cause the monitorAndWait to block
even when a connection or channel is actually closed. This happens
because the consumers or publishers can close the channel due to an
error inside their respective goroutines.

This fix also avoids starting and leaking a bunch of goroutines inside
monitorAndWait.
This enables a request to be canceled when it's context is canceled.
Perhaps due to an external timeout.

This also removes the chanSendWaitTime in favor of a context cancel.

When a user sets a shorter deadline with a cause on the context, that
cause will be returned by Send when the method returns.
@akarl akarl marked this pull request as ready for review December 6, 2024 15:11
@akarl akarl requested a review from bombsimon December 6, 2024 15:11
Copy link
Member

@bombsimon bombsimon left a comment

Choose a reason for hiding this comment

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

Really nice condensing 3 channels to one! And nice using proper context cancellation and having the user controlling cancelation as one would expect!

LGTM (just some nits in the readme).

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
request.go Show resolved Hide resolved
client.go Show resolved Hide resolved
@akarl akarl enabled auto-merge December 9, 2024 08:57
@akarl akarl merged commit 3f90bc5 into master Dec 9, 2024
2 checks passed
@akarl akarl deleted the graceful-client branch December 9, 2024 08:57
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