Skip to content

Commit 1aa0cfa

Browse files
authored
Fix s3 transfer dead lock (#96)
* Fix race condition in TransferHandle::WaitUntilFinished() deadlocking #511 #520
1 parent 09d1ccd commit 1aa0cfa

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

aws-cpp-sdk-transfer/source/transfer/TransferHandle.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ namespace Aws
229229

230230
if(IsTransitionAllowed(currentStatus, value))
231231
{
232+
std::unique_lock<std::mutex> semaphoreLock(m_statusLock);
232233
m_status.store(static_cast<long>(value));
233234

234235
if (IsFinishedStatus(value))
@@ -238,20 +239,18 @@ namespace Aws
238239
CleanupDownloadStream();
239240
}
240241

241-
std::unique_lock<std::mutex> semaphoreLock(m_statusLock);
242242
m_waitUntilFinishedSignal.notify_all();
243243
}
244244
}
245245
}
246246

247247
void TransferHandle::WaitUntilFinished() const
248248
{
249+
std::unique_lock<std::mutex> semaphoreLock(m_statusLock);
249250
if (!IsFinishedStatus(static_cast<TransferStatus>(m_status.load())) || HasPendingParts())
250251
{
251-
std::unique_lock<std::mutex> semaphoreLock(m_statusLock);
252252
m_waitUntilFinishedSignal.wait(semaphoreLock, [this]()
253253
{ return IsFinishedStatus(static_cast<TransferStatus>(m_status.load())) && !HasPendingParts(); });
254-
semaphoreLock.unlock();
255254
}
256255
}
257256

@@ -301,4 +300,4 @@ namespace Aws
301300
}
302301
}
303302
}
304-
}
303+
}

aws-cpp-sdk-transfer/source/transfer/TransferManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,9 @@ namespace Aws
501501
}
502502
else
503503
{
504-
transferContext->handle->UpdateStatus(DetermineIfFailedOrCanceled(*transferContext->handle));
505504
transferContext->handle->ChangePartToFailed(transferContext->partState);
506505
transferContext->handle->SetError(outcome.GetError());
506+
transferContext->handle->UpdateStatus(DetermineIfFailedOrCanceled(*transferContext->handle));
507507
TriggerErrorCallback(*transferContext->handle, outcome.GetError());
508508
}
509509

0 commit comments

Comments
 (0)