fix deadlock at TransferHandle::WaitUntilFinished #520
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I encountered a deadlock when calling WaitUntilFinish, for transfer request which failed. i tried to upload to non existent bucket. from time to time, my process got deadlock. The reason is that transferContext->handle->UpdateStatus method shall be called last, after the part status was changed (and this is the fix).
The waiting thread is waiting on conditional variable and being notified when object status is changed to finished status. however the predicate it uses checks also it does not have pending parts.
A deadlock can occur if the transfer manager change the object status to failed and notify the waiting thread to be awaken, however it did not yet changed the part status, so it is regarded as pending part.
so waiting thread is awaken, checks the predicate and enter a sleep. now no one will awake it again, and this result with deadlock.
If you look at HandlePutObjectResponse you can see, it first change the part status and then the object status. the same behavior shall be done for failed case. I also put the SetError to be before the UpdateStatus call, as thread which is waiting may want to observe the error message on failure case.