Fix race in ScanIteratorBase.Dispose causing intermittent ObjectDisposedException#1667
Merged
Conversation
51e69c5 to
05e9f4b
Compare
Two changes to Dispose(): 1. Move 'loadCompletionEvents = default' from inside the per-frame loop to after the loop. With frameSize=2, the old code nulled the entire array on the first iteration (i=0), causing iteration i=1 to skip waiting for its in-flight async read. The read callback (AsyncReadPageWithObjectsCallback) would then access the already-disposed CircularDiskReadBuffer, crashing the test host with an unhandled ObjectDisposedException. 2. Separate the Wait (which can throw on cancellation) from resource cleanup. The event, CTS, and read buffer disposals now run unconditionally after the try/catch, ensuring resources are always cleaned up even when the wait fails. Co-authored-by: Copilot <[email protected]>
05e9f4b to
08ae91c
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an intermittent ObjectDisposedException during disk-scan iterator teardown by ensuring all per-frame async page-load completion events are awaited and disposed correctly (especially important under double-page buffering).
Changes:
- Refactors
ScanIteratorBase.Dispose()to wait on each frame’sloadCompletionEvents[i]before disposing associated resources. - Moves
loadCompletionEvents = defaultto after the per-frame loop to avoid prematurely nulling the array. - Ensures completion events, cancellation token sources, and read buffers are disposed even if the wait throws.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes an intermittent test host crash (ObjectDisposedException: Cannot access a disposed object. Object name: 'CircularDiskReadBuffer') observed in CI during InsDelIns_LocalMemory.
Root cause: In ScanIteratorBase.Dispose(), loadCompletionEvents = default was inside the per-frame loop, nulling the entire array after processing frame 0. With DoublePageBuffering (frameSize=2), frame 1's completion event was never waited on, so its CircularDiskReadBuffer was disposed while AsyncReadPageWithObjectsCallback was still using it on a thread pool thread.
Fix: Move loadCompletionEvents = default from inside the loop to after the loop, ensuring all frames are properly awaited before their read buffers are disposed.