Skip to content

SimpleStateMachine.DisposeAsync leaves a completed snapshot writer open #313

Closed

Description

@tuk1976

SimpleStateMachine.DisposeAsync() can leave the temporary snapshot writer open when a snapshot has finished writing but no later log entry has applied it. This is reproducible with the unmodified DotNext.Net.Cluster 6.12.0 package and is still present on develop at 8d81cad5ce29baafb88cab9be4b15b1c2f14f766.

Expected: disposing the state machine releases its writer and discards any unpublished temporary snapshot, preserving the last published snapshot and the WAL.

Observed on Windows x64 (.NET 10.0.14): disposal returns, but the temporary file remains open with exclusive sharing and directory cleanup throws IOException. Disposing the WAL before the state machine and calling state disposal a second time do not fix it.

The standalone diagnostic produced these results (10 runs per scenario):

Scenario Writer/cleanup failure Correct state recovery
Snapshot creation disabled 0/10 10/10
Completed, unpublished snapshot 10/10 10/10
Same, with WAL flush and a 250 ms wait 10/10 10/10
Another committed entry publishes the prior snapshot 0/10 10/10

This is a shutdown resource-cleanup defect; these tests do not show state loss. A borrowed writer reference is retained in the diagnostic so garbage collection cannot hide a missing deterministic disposal.

The source path appears to be:

  1. BeginSnapshottingAsync returns a successfully written/flushed SnapshotWriter that is still open.
  2. The next ApplyCoreAsync normally installs the snapshot, closing that writer.
  3. DisposeImplAsync instead waits for the snapshot task with SuppressThrowing and discards its successful result. The existing rollback path is not called.

Fix and regression tests: #314. SimpleStateMachineTests is included in the normal xUnit test project. The completed-snapshot cases assert the public writer is disposed and the temporary files are gone, including preservation of an existing published snapshot; cancellation/failure/no-snapshot cases are controls. On the unchanged implementation, exactly the two completed-snapshot cases fail and the other three pass.

Test command:

dotnet test --project src/DotNext.Tests/DotNext.Tests.csproj --filter-class "*.SimpleStateMachineTests"

Prepared with AI assistance; the reproduction and source path were independently reviewed.

Activity

  1. added theissue type on Nov 8, 2026
  2. linked a pull request that will close this issueFix disposal of completed unpublished snapshots #314on Nov 8, 2026
  3. added
    ai_assistedBug or PR is produced partially or fully by the AI model (Codex, Claude, etc.)
    on Nov 8, 2026
  4. sakno commented on Nov 9, 2026

    @sakno
    Collaborator

    Fixed in 6.12.1.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Lib:ClusterDotNext.Net.Cluster libraryai_assistedBug or PR is produced partially or fully by the AI model (Codex, Claude, etc.)

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions