Skip to content

[P2] Guard recycle-bin checkpoint reads before I/O in sync and async cleanup #107

Closed

Description

@AGiorgetti

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

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:

  1. Call each public cleanup method. Inject a sentinel MongoException, then MongoConnectionException, from FindSync/FindAsync and separately from MoveNext/MoveNextAsync.
  2. 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.
  3. 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 ObjectDisposedException with 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions