Fix retire/release race condition when resource close yields#25
Open
wtn wants to merge 1 commit intosocketry:mainfrom
Open
Fix retire/release race condition when resource close yields#25wtn wants to merge 1 commit intosocketry:mainfrom
wtn wants to merge 1 commit intosocketry:mainfrom
Conversation
Co-authored-by: Claude <noreply@anthropic.com>
Author
|
Force-pushed to fix Rubocop violations. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When
retireis called on a resource whosecloseyields (e.g. an HTTP/2 connection sending GOAWAY), another fiber can callreleaseon the same resource and hitRuntimeError: Trying to reuse unacquired resource.This occurs because
retiredeletes from@resourcesbefore callingresource.close. If close yields, the resource is no longer tracked but still reportsreusable? = true, sorelease→reusefinds nil usage and raises.How we triggered it
Using
async-httpwith HTTP/2 under sustained load (~500+ req/sec), server-initiated connection resets trigger this regularly, affecting ~1.5% of requests in our scenario. The background reader callspool.retire(connection), thenAsync::HTTP::Client#call's rescue handler callspool.release(connection)on the same resource. TheRuntimeErrorreplaces the original retriable error, so requests fail instead of being retried.The fix
@retiringset tracks resources currently mid-close insideretireretireis made idempotent — returns false if the resource was already deletedreusereturns false when the resource is in@retiring, soreleasesilently handles the already-retired resourceTypes of Changes
Contribution
Note
Any changes are OK with me.