Skip to content

Commit 5eae79c

Browse files
committed
Make sure to reset hEvent on error while locking a chunk
Otherwise WriteFile() fails with ERROR_INVALID_HANDLE in PostWriteChunk() for example. The file system may regard this as loss of data.
1 parent b213a8f commit 5eae79c

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

worker.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,13 +1544,22 @@ DWORD ChunkDiskWorker::PostLockChunk(ChunkOpState& state, const u64 chunk_idx, c
15441544

15451545
auto* user = LPVOID(&state);
15461546
auto err = service_.LockChunk(chunk_idx, user);
1547-
if (err == ERROR_LOCKED) return WaitChunkAsync(chunk_idx, &state); // LOCK_CHUNK may not have been handled yet
1548-
if (err != ERROR_SUCCESS) return err;
1547+
if (err == ERROR_LOCKED)
1548+
{
1549+
state.ovl.hEvent = nullptr;
1550+
return WaitChunkAsync(chunk_idx, &state); // LOCK_CHUNK may not have been handled yet
1551+
}
1552+
if (err != ERROR_SUCCESS)
1553+
{
1554+
state.ovl.hEvent = nullptr;
1555+
return err;
1556+
}
15491557

15501558
if (create_new && service_.bases[0].CheckChunk(chunk_idx))
15511559
{
15521560
// lock no longer required
15531561
service_.UnlockChunk(chunk_idx);
1562+
state.ovl.hEvent = nullptr;
15541563
return ERROR_SUCCESS;
15551564
}
15561565

@@ -1579,6 +1588,7 @@ DWORD ChunkDiskWorker::PostLockChunk(ChunkOpState& state, const u64 chunk_idx, c
15791588
if (err != ERROR_SUCCESS)
15801589
{
15811590
service_.UnlockChunk(chunk_idx);
1591+
state.ovl.hEvent = nullptr;
15821592
return err;
15831593
}
15841594

@@ -1607,11 +1617,11 @@ DWORD ChunkDiskWorker::LockingChunk(const u64 chunk_idx)
16071617
DWORD ChunkDiskWorker::PostUnlockChunk(ChunkOpState& state, const u64 chunk_idx)
16081618
{
16091619
// cleanup
1620+
service_.UnlockChunk(chunk_idx);
16101621
state.ovl.Internal = 0;
16111622
state.ovl.InternalHigh = 0;
16121623
state.ovl.hEvent = nullptr;
16131624

1614-
service_.UnlockChunk(chunk_idx);
16151625
auto err = DWORD(ERROR_SUCCESS);
16161626

16171627
for (auto& worker : GetWorkers(service_.storage_unit))

0 commit comments

Comments
 (0)