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.
Description:
This PR fixes a possible deadlock bug in stratumserver.
There are two Read locks on
self.current_state
inbuild_block_template()
at L347 and L348.The first Read lock is not released before calling the second lock.
The lock
self.current_state
is aparking_lot::RwLock
.According to the doc of
parking_lot::RwLock
:“readers trying to acquire the lock will block even if the lock is unlocked when there are writers waiting to acquire the lock.”
“attempts to recursively acquire a read lock within a single thread may result in a deadlock.”
Therefore, a deadlock may happen when a write lock interleaves the two read locks.
How I fix:
Use one read lock instead of two.
Other Concerns:
I notice that
bh
is also computed fromself.current_state
.Suppose that thread-A computes
bh
,thread-B changes
self.current_state
,then thread-A computes
job_template
. Is this interleaving okay?