Repository navigation
Description
Summary
Both EmptyRecycleBin() and EmptyRecycleBinAsync(...) read the last committed checkpoint before entering their MongoDB exception/disposal guard. The delete is guarded, but the preceding database read is not.
Priority: P2 (error-contract correctness and use-after-disposal prevention). Confirmed by source inspection on develop 8f580f1a; the same ordering remains at #106 head e5ea11b6. The reproduction below is a deterministic test recipe, not a newly executed runtime result.
Evidence and impact
- Synchronous checkpoint lookup and cleanup:
FindSync(...).FirstOrDefault()runs beforeTryMongo. - Asynchronous checkpoint lookup and cleanup:
FindAsyncandFirstOrDefaultAsyncrun beforeTryMongoAsync. - The sync guard and async guard check disposal and translate
MongoConnectionExceptiontoStorageUnavailableException, and otherMongoExceptioninstances toStorageException.
Consequently, a driver failure during checkpoint acquisition or cursor advancement escapes untranslated. An already-disposed engine can attempt the checkpoint read before raising ObjectDisposedException; if that read fails, its error can mask disposal. A read failure prevents the delete from being reached. No data loss is established here.
Deterministic reproduction
Use an instrumented protected PersistedCommits collection and fake cursor, without relying on a real network outage:
- Call each public cleanup method. Inject a sentinel
MongoException, thenMongoConnectionException, fromFindSync/FindAsyncand separately fromMoveNext/MoveNextAsync. - Check the surfaced error: the current control flow exposes the sentinel rather than the appropriate storage wrapper. Assert that no delete occurs and any acquired cursor is disposed.
- Dispose the engine before invoking cleanup. Make the checkpoint seam record access and return successfully. The current ordering reaches that seam before the disposal guard; the desired result is
ObjectDisposedExceptionwith no collection access or database operation.
Acceptance criteria and risks
- Guard the whole read-then-delete operation in both APIs, checking disposal before the first database access.
- Cover acquisition and advancement failures, wrapper type and original inner exception, ordinary non-driver exception identity, cursor disposal, and no deletion after a failed read.
- Preserve async cancellation/token propagation and the genuine asynchronous acquisition fixed by [P2] Async checkpoint reads execute FindSync before returning their Task #88/Fix asynchronous checkpoint cursor acquisition (#88) #103.
- Preserve the cleanup predicate: delete only recycle-bin records below the selected highest checkpoint. Cover empty stores, a highest checkpoint inside/outside the recycle bin, and failure before deletion.
- Document the exception-compatibility change for consumers catching raw MongoDB exceptions. Avoid nested/double translation and review protected virtual guard compatibility.
This is separate from #91/#106 (deferred synchronous enumerable reads), closed #88/#103 (async checkpoint acquisition), and #96 (stream lifecycle/checkpoint-retention redesign). Existing #88 regression tests use an InvalidOperationException sentinel and do not establish MongoDB exception translation.
Co-authored by Alessandro Giorgetti and Codex (OpenAI).
Activity
fix: guard recycle-bin checkpoint reads before I/O (#107)