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

Potential race condition in p2p.switch.reconnectToPeer() and pex_reactor #7014

Closed
lklimek opened this issue Sep 28, 2021 · 0 comments · Fixed by #7015
Closed

Potential race condition in p2p.switch.reconnectToPeer() and pex_reactor #7014

lklimek opened this issue Sep 28, 2021 · 0 comments · Fixed by #7015

Comments

@lklimek
Copy link

lklimek commented Sep 28, 2021

Tendermint version master (revision 6be3661)

What happened:

When reviewing the code, I have noticed two potential race condition bugs:

Here's the faulty code:

1. if r.requestsSent.Has(id) {
2.   return
3. }
4. r.requestsSent.Set(id, struct{}{})

If two goroutines enter these functions at the same time, they both can pass the Has() condition in line 1 (as it's not set yet), and then, both execute the Set() operation from line 4 in random order, resulting in a non-deterministic behavior.

A possible solution is to use an approach similar to sync.Map.LoadOrStore() to do operations from lines 1 and 4 together, in an atomic way.

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 a pull request may close this issue.

1 participant