-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-30285][CORE] Fix deadlock between LiveListenerBus#stop and AsyncEventQueue#removeListenerOnError #26924
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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
03a41d1
Fix race condition between LiveListenerBus#stop and AsyncEventQueue#r…
wangshuo128 781caba
Fix UT
wangshuo128 7b8b1fa
Address review feedback
wangshuo128 c2afd63
Fix UT
wangshuo128 3260be1
Remove synchronized in LiveListenerBus.stop
wangshuo128 3d7f435
Fix UT, address some review feedback
wangshuo128 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you trying to make sure listeners throw the exception after "stop()" is called? That's going to be hard, and your code isn't really guaranteeing that.
You could use a
CountDownLatch
that you signal right before callingstop()
(in the thread) to unblock the listener; that will at least narrow the race down a bit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could check the
stopped
status ofbus
in the listener.This would be better than using a
CountDownLatch
, however, it can't get rid of racing completely. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CountDownLatch
always make things deterministic and it sounds better to me.What do you mean by "it can't get rid of racing completely"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the PR description, to reproduce the original issue, we have to make sure:
bus
in the stopping threadbus
in the interrupting listener threadBut signal the listener starts to interrupt just before
bus.stop
by aCountDownLatch
can't guarantee this 100%, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, you should insert
CountDownLatch
afterbus.stop
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, you want to let
interruptingListener
start to work oncebus
has moved tostop
status and acquired the synchronized lock, right?But how can
bus
acquired the synchronized lock now? This fix has already removed the synchronized lock. The only thing you could do is to checkbus
status now and I think it's enough.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got your point.
Now, there are two things.
For (1), we can't avoid racing without changing the
bus.stop
code (e.g. add a callback).For (2), we at least have to expose the internal
stoped
status ofbus
, which maybe is not recommended.So WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only focus on
LiveListenerBus
may be impossible to workaround the difficulties you mentioned above. Maybe we should move toAsyncEventQueue
.How about this way:
Add a method
status()
inAsyncEventQueue
for testing only;In
interruptingListener
, keep checkingAsyncEventQueue.status()
until it's stopped. So, whenAsyncEventQueue
is stopped, we're sure thatLiveListenerBus
has stopped too and acquired the lock(without fix).WDYT?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this would work. In
AsyncEventQueue
, in fact, there is also astoped
status that we could check.But associating a listener with its
AsyncEventQueue
would be another problem we have to resolve. Currently, it's encapsulated bybus.addToXXXQueue
inside the bus code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You guys are trying to fabricate a test that will not be testing what the actual code is doing when a real app is running. That's the problem.
To do that you'd need the
stop()
code in the listener bus to wait holding a lock while the queues are being drained; and one of those queues need to run into the error that causes it to remove a bad listener. That's hard to do without inserting callbacks that don't exist into the code; and adding those callbacks would only be enabling the test, which is why that's questionably.So you basically need this in the new
stop()
:The two callbacks are needed because otherwise there is no guarantee that what the queues do will happen before
stop()
does its thing.But really I don't see what really that test would be actually testing now that there is no synchronized block anymore.
Anything you do here without these callbacks will be racy, and thus may not hit the original issue. Also, without the synchronized block, there's nothing to cause a deadlock in the first place, so that's why I said the test isn't that great to begin with.
So I'd avoid trying to create a fancy test that isn't really testing the issue and just adding unneeded hooks into the main code. The current test is ok and as close as you'll get without the above callbacks; so either go with that, or just remove the test.