-
Notifications
You must be signed in to change notification settings - Fork 294
Fixes #1482, removed unsafe double RLock #1525
Fixes #1482, removed unsafe double RLock #1525
Conversation
What makes the double RLock unsafe and how is it related to #1482? |
in golang documentation (https://golang.org/src/sync/rwmutex.go) there is following information: // If a goroutine holds a RWMutex for reading, it must not expect this or any
// other goroutine to be able to also take the read lock until the first read
// lock is released. In particular, this prohibits recursive read locking.
// This is to ensure that the lock eventually becomes available;
// a blocked Lock call excludes new readers from acquiring the lock. I've also found this issue: golang/go#15418. |
control/strategy/pool.go
Outdated
@@ -361,10 +361,8 @@ func (p *pool) SubscriptionCount() int { | |||
} | |||
|
|||
// SelectAP selects an available plugin from the pool | |||
// the method is not thread safety, it should be protected outside of the body |
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.
s/safety/safe/
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.
Corrected :]
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.
LGTM once @IRCody also gives a +1
Thanks for the links. That's an interesting and subtle difference (more subtle if you read the entire comment on the type). Do we want the locks to be removed from inside pool or for them to be used inside pool only? Other pool functions contain the same code for locking/unlocking that we are removing here, do they have a similar bug? |
20f15b2
to
ac9e9bf
Compare
I've found one more double RLock in I anlyzed locking of pool and pool is locked outside only three times in: |
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.
WIP - Do not merge. Testing using the harness @katarzyna-z provided is still underway. We are seeing failures on a multi core physical system that have yet to be understood. On dev systems and VMs with multiple cores the test harness works (with the PR) as expected.
The changes in this PR do seem to fix some pretty serious issues that are identified by the script. The failures we were seeing were a fail by the tester(me) and not the PR 👎 . With fresh eyes the fix works as described/expected. I think we might want to have more discussion about whether we want the pool mutex to be locked from inside or outside the pool. I think it might be confusing to do both (since that is at least partially what led to this issue). I know after talking with @jcooklin about it that we want to have some consistency. Maybe we can have that discussion here? |
I've updated the PR - I moved Rlocks outside pool to |
I agree. LGTM after removing latest commit. |
ac9e9bf
to
70d5b5e
Compare
Removed double RLock in (p *pool) Eligible() Replaced lock for reading with lock for writing (RLock/RUnlock -> Lock/Unlock) in (p *pool) IncRestartCount
LGTM |
Fixes #1482
Summary of changes:
SelectAP()
in these lines: L404, L453, L487Testing done:
@intelsdi-x/snap-maintainers