Skip to content

Commit 02186c0

Browse files
authored
Merge pull request #274 from suleymanbyzt/develop
Snapshot file handle not closed in RestoreAsync causes delete error on Windows
2 parents ba0901f + 9357121 commit 02186c0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/examples/RaftNode/StateMachine.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ public StateMachine(IConfiguration config)
2323

2424
protected override async ValueTask RestoreAsync(FileInfo snapshotFile, CancellationToken token)
2525
{
26-
var handle = File.OpenHandle(snapshotFile.FullName, options: FileOptions.Asynchronous);
27-
var buffer = new byte[sizeof(long)];
26+
byte[] buffer = new byte[sizeof(long)];
27+
using var handle = File.OpenHandle(
28+
snapshotFile.FullName,
29+
FileMode.Open,
30+
FileAccess.Read,
31+
FileShare.ReadWrite | FileShare.Delete,
32+
FileOptions.Asynchronous | FileOptions.SequentialScan);
33+
2834
await RandomAccess.ReadAsync(handle, buffer, fileOffset: 0L, token).ConfigureAwait(false);
2935
Value = BinaryPrimitives.ReadInt64LittleEndian(buffer);
3036
}
@@ -60,4 +66,4 @@ static long ToInt64(in ReadOnlySequence<byte> sequence)
6066
return BinaryPrimitives.ReadInt64LittleEndian(buffer);
6167
}
6268
}
63-
}
69+
}

0 commit comments

Comments
 (0)