fix: replace dedup resolver closure chain with array to prevent hangs#25
Merged
1bcMax merged 1 commit intoBlockRunAI:mainfrom Feb 14, 2026
Merged
Conversation
The previous implementation chained waiters by patching entry.resolve via closures. This was fragile and hard to reason about. More critically, removeInflight() (called on client disconnect or request error) deleted the inflight entry without resolving pending waiters — causing them to hang forever with no response. Changes: - Replace closure-chain pattern with a simple resolvers array - On complete(): iterate all resolvers and resolve each one - On removeInflight(): resolve waiters with 503 error instead of leaving them hanging, so clients can retry independently Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
RequestDeduplicatorwith a simpleresolversarrayremoveInflight()silently dropping waiters — they now receive a 503 response instead of hanging foreverProblem
1. Closure chain is fragile and hard to reason about:
The old
getInflight()chained each new waiter by capturing and wrapping the previousentry.resolvevia closures:This pattern is hard to verify for correctness and makes the code unnecessarily complex.
2.
removeInflight()causes waiters to hang forever (real bug):When the original request fails (client disconnect, timeout, error),
removeInflight()was called which simply deleted the inflight entry:Any waiters (
getInflight()callers) would have promises that never resolve, causing those HTTP responses to hang indefinitely until the client times out.Fix
InflightEntrynow holdsresolvers: Array<(result) => void>instead of a singleresolvefunction +waitersarraycomplete()iterates all resolversremoveInflight()resolves all waiters with a 503 error response so they can retry independentlyTest plan
npm run build🤖 Generated with Claude Code