Fix race condition in SequenceToPaginatedResponseAdapter timeout eviction#72
Merged
nerzhulart merged 2 commits intoagentclientprotocol:masterfrom Feb 27, 2026
Conversation
nerzhulart
approved these changes
Feb 27, 2026
c5d00b6 to
2bbc639
Compare
…aginated-response-adapter
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.
Problem
SequenceToPaginatedResponseAdapterhad a race condition in cursor eviction. When a new cursor was created, the timeout job was launched immediately vialaunch { ... }, but the cursor was stored in the map only after the launch. With very shortorphanedIteratorsEvictionTimeoutvalues, the timeout job could fire and callmap.remove(cursor)beforemap.put(cursor, ...)had executed. This left the cursor permanently in the map with no eviction job, effectively leaking the iterator.Fix
Changed the timeout job to use
CoroutineStart.LAZYso it is created but not started until after the cursor is stored in the map. The job is then explicitly started withtimeoutJob.start(), guaranteeing the correct ordering:This eliminates the race condition regardless of how short the eviction timeout is