[STORM-3658] Avoid deadlock and race condition caused by shutdown hooks #3299
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.
What is the purpose of the change
Details explained in https://issues.apache.org/jira/browse/STORM-3658.
In short, the problem here is
How was the change tested
prepare
method. Use it to validate the change. The race condition and deadlock is not happening.The log below shows shutdown hook waited for 100ms and continue. This avoids the deadlock.
Adding shutdown hook with kill in 3 secs
message appears very early. And I added a bug in my test to print out thread dump right after registering the shutdown hook. The only alive threads at that point areAnd also tested with the above topology and don't see race condition happen again (while it was very easy to happen before the code change)
workerstate
could be null if exception happens beforeworkerstate
object is initialized properly. This was tested by throwing an exception beforeworkerstate
construction is all done. And the modified shutdown method doesn't throw NPE.