[release/1.1] Fix context cancelled error after client close #160
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
#137
Description
Closes the receiver goroutine without setting the client error when the client is closed. Client error will be set on next dispatch call invoked if any.
Testing
Adds unit test which calls test service call after client is closed. Before the change, the test failed 1 in every ~3000 runs. After the change, the test passed successfully 10000 runs in a row.
Run test:
Test failure without fix:
Output:
Alternative solutions considered
Considered setting the client error to
ErrClosed
when the receive goroutine exits on context cancel. I decided against this as closing the client is not an error until a call is made on a closed client which would result in the error being set toErrClosed
.