Skip to content
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

THRIFT-4237 Fix effective deadlock introduced by original patch #1304

Closed
wants to merge 1 commit into from

Conversation

zwass
Copy link
Contributor

@zwass zwass commented Jul 7, 2017

defer p.mu.RUnlock()
listener := p.listener
interrupted := p.interrupted
p.mu.RUnlock()

Copy link

Choose a reason for hiding this comment

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

Hmm. It seems safest to me to unlock this mutex after the value of interrupted has been read (assuming it is only intended to protect interrupted).

For example,
Thread 1 reads the value of interrupted as false
Thread 1 gets interrupted at line 74
Thread 2 sets p.interrupted to true
Thread 1 sees interrupted == false at line 75

The question is would we want thread 1 to see interrupted == true ?

This is possibly a case that does not happen. I have very limited knowledge of what this code is doing.

Copy link
Member

Choose a reason for hiding this comment

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

Agree. Looks strange. and the comment even says

  // Protects the interrupted value to make it thread safe.

What about moving the listener := p.listener line down just before it is used? Or do I overlook sth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will admit I also only have limited knowledge of what the code is doing. I am guessing as to the intended behavior based on the implementation. Is the expected behavior documented somewhere?

@econner This is something I considered, and here's what I reasoned out:
Ideally, we would ensure that the scenario you describe does not take place by continuing to hold the lock. In reality, the call to listener.Accept() may block, and if the lock was held this would prevent the Interrupt() method from acquiring the lock (resulting in the "deadlock" experienced previously). In the case that the instructions are interleaved as you describe, we will still return an error (albeit a different one) on line 84.

@Jens-G That does look viable to me.

@asfgit asfgit closed this in 5e9209f Jul 8, 2017
jeking3 pushed a commit to jeking3/thrift that referenced this pull request Aug 5, 2017
Client: Go
Patch: Zachary Wasserman <zachwass2000@gmail.com>

This closes apache#1304
jeking3 pushed a commit to jeking3/thrift that referenced this pull request Nov 30, 2017
Client: Go
Patch: Zachary Wasserman <zachwass2000@gmail.com>

This closes apache#1304
hsanjuan pushed a commit to gxed/thrift-go that referenced this pull request Jan 30, 2019
Client: Go
Patch: Zachary Wasserman <zachwass2000@gmail.com>

This closes apache#1304
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