Skip to content

fix deadlock at TransferHandle::WaitUntilFinished #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

fix deadlock at TransferHandle::WaitUntilFinished #520

wants to merge 1 commit into from

Conversation

Eliyahu-Machluf
Copy link

@Eliyahu-Machluf Eliyahu-Machluf commented May 9, 2017

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.

…d is notified when status is changed to finished, however it checks also if there are no pending parts. so if it got notified before part status was changed, it encounter deadlock. the right order is first change part status and then change the object status to failed
Copy link
Contributor

@JonathanHenson JonathanHenson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Will merge shortly

JonathanHenson pushed a commit that referenced this pull request May 12, 2017
* Fix race condition in TransferHandle::WaitUntilFinished() deadlocking
#511 #520
@singku
Copy link
Contributor

singku commented May 12, 2017

Merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants