-
Notifications
You must be signed in to change notification settings - Fork 233
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
Fix disconnect race. #2088
base: unstable
Are you sure you want to change the base?
Fix disconnect race. #2088
Conversation
11ead9d
to
ee0a025
Compare
beacon_chain/eth2_network.nim
Outdated
# All the `peer.disconnectedFut` callbacks are already scheduled in current | ||
# `poll()` call, to avoid race we going to finish only in next `poll()` | ||
# call. | ||
callSoon(continuation, cast[pointer](retFuture)) |
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.
the pointer isn't needed here
Add isAlive(peer) procedure. Add join(peer) procedure. Remove useless metric. Add notifyAndWait() procedure which will help to avoid race while disconnecting.
notifyAndWait() now waits PeerPool and disconnection.
ee0a025
to
4957ae8
Compare
block: | ||
var fut0 = pool.joinPeer(peer0) | ||
doAssert(fut0.finished == false) | ||
await sleepAsync(20.milliseconds) |
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.
can't we use the step polling here instead?
if not(isNil(fut)): | ||
fut.complete() | ||
peer.disconnectedFut = nil | ||
if not(isNil(peer.disconnectedFut)): |
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.
shouldn't this check be inside notifyAndWait
?
# All the `peer.disconnectedFut` callbacks are already scheduled in current | ||
# `poll()` call, to avoid race we going to finish only in next `poll()` | ||
# call. | ||
callSoon(continuation, cast[pointer](retFuture)) |
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.
continuation does not use its udata
pointer - why include a pointer here?
657f9d5
to
a4667d1
Compare
PeerPool
to usegetFuture()
only once when adding peer.isAlive(peer)
procedure.join(peer)
procedure.notifyAndWait()
procedure which will help to avoid race while disconnecting.