Skip to content

Commit

Permalink
S3Read: fix race condition that could result in read data being trunc…
Browse files Browse the repository at this point in the history
…ated.
  • Loading branch information
Bob Kast committed Oct 10, 2019
1 parent 0799b1d commit 16e6b70
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
67 changes: 32 additions & 35 deletions ECSUtil/FileSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,50 +215,47 @@ CECSConnection::S3_ERROR S3Read(
dwMainThreadError = ERROR_OPERATION_ABORTED;
break;
}
if (ReadThread.bWorkerDone)
break;
// check if the background thread has ended with an error
if (!ReadThread.IfActive() && ReadThread.Error.IfError())
break;
if (ReadThread.GetExitFlag())
{
// the thread has called KillThread()
dwMainThreadError = ERROR_OPERATION_ABORTED;
break;
}
if (dwError == WAIT_FAILED)
{
dwMainThreadError = GetLastError();
break;
}
if (dwError == WAIT_OBJECT_0)
{
// got an event that something was pushed on the queue
while (!ReadThread.ReadContext.StreamData.empty())
while (!ReadThread.ReadContext.StreamData.empty())
{
CECSConnection::STREAM_DATA_ENTRY StreamData;
DWORD dwNumWritten;
{
CECSConnection::STREAM_DATA_ENTRY StreamData;
DWORD dwNumWritten;
{
CRWLockAcquire lockQueue(&ReadThread.ReadContext.StreamData.GetLock(), true); // write lock
StreamData = ReadThread.ReadContext.StreamData.front();
ReadThread.ReadContext.StreamData.pop_front();
}
// write out the data
if (!StreamData.Data.IsEmpty())
{
dwError = pStream->Write(StreamData.Data.GetData(), StreamData.Data.GetBufSize(), &dwNumWritten);
if (dwError != S_OK)
return dwError;
if (UpdateProgressCB != nullptr)
UpdateProgressCB(dwNumWritten, pContext);
}
if (StreamData.bLast)
{
bDone = true;
break; // done!
}
CRWLockAcquire lockQueue(&ReadThread.ReadContext.StreamData.GetLock(), true); // write lock
StreamData = ReadThread.ReadContext.StreamData.front();
ReadThread.ReadContext.StreamData.pop_front();
}
// write out the data
if (!StreamData.Data.IsEmpty())
{
dwError = pStream->Write(StreamData.Data.GetData(), StreamData.Data.GetBufSize(), &dwNumWritten);
if (dwError != S_OK)
return dwError;
if (UpdateProgressCB != nullptr)
UpdateProgressCB(dwNumWritten, pContext);
}
if (StreamData.bLast)
{
bDone = true;
break; // done!
}
}
if (ReadThread.GetExitFlag())
{
// the thread has called KillThread()
dwMainThreadError = ERROR_OPERATION_ABORTED;
break;
}
if (ReadThread.bWorkerDone)
break;
// check if the background thread has ended with an error
if (!ReadThread.IfActive() && ReadThread.Error.IfError())
break;
}
// now wait for the worker thread to terminate to get its error code
ReadThread.KillThreadWait();
Expand Down
2 changes: 1 addition & 1 deletion ECSUtil/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

#define ECSUTIL_COPYRIGHT _T("Copyright © 2019 Dell Inc. or its subsidiaries.")

#define ECSUTIL_VERSION "v1.0.7.7"
#define ECSUTIL_VERSION "v1.0.7.8"

0 comments on commit 16e6b70

Please sign in to comment.