-
Notifications
You must be signed in to change notification settings - Fork 476
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
network: handle empty wsPeer supplied to transaction handler #6195
base: master
Are you sure you want to change the base?
network: handle empty wsPeer supplied to transaction handler #6195
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6195 +/- ##
==========================================
+ Coverage 51.88% 51.91% +0.02%
==========================================
Files 639 639
Lines 85489 85495 +6
==========================================
+ Hits 44359 44382 +23
+ Misses 38320 38301 -19
- Partials 2810 2812 +2 ☔ View full report in Codecov by Sentry. |
@@ -282,6 +282,8 @@ type wsPeer struct { | |||
|
|||
// closers is a slice of functions to run when the peer is closed | |||
closers []func() | |||
// closersMu synchronizes access to closers | |||
closersMu deadlock.RWMutex |
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.
Oh interesting, so you spotted a race in wsNetwork when txHandler is processing multiple messages from the same peer
@@ -979,6 +976,8 @@ L: | |||
} | |||
|
|||
} | |||
wp.closersMu.RLock() | |||
defer wp.closersMu.RUnlock() |
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.
Nice catch
@@ -1115,6 +1114,9 @@ func (wp *wsPeer) sendMessagesOfInterest(messagesOfInterestGeneration uint32, me | |||
} | |||
|
|||
func (wp *wsPeer) OnClose(f func()) { | |||
wp.closersMu.Lock() |
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.
Not directly related to this PR, but its' odd to me that the same type has both a Close()
and OnClose()
with minimal overlap.
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.
wsPeer.OnClose(f)
actually means "register a function f
to be called when wsPeer closes."
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.
I'm generally okay with this pending questions CCE asked.
I'd probably add one additional sentence or a title tweak highlighting the problem being solved (it's a race condition that folks ran into on mainnet as I recall, just took some digging to find).
gossip or gossipSub |
} | ||
|
||
func (p *gsPeer) RoutingAddr() []byte { | ||
return []byte(p.peerID) |
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.
Some day, we could consider calling net.Network().ConnsToPeer(p.peerID), and then getting an IP address here, but it seems like an expensive thing to do per-message, and we are likely going to have a wsPeer conn appear soon anyway that we can get the IP address from.
@@ -1401,7 +1401,7 @@ func (wn *msgBroadcaster) innerBroadcast(request broadcastRequest, prio bool, pe | |||
if wn.config.BroadcastConnectionsLimit >= 0 && sentMessageCount >= wn.config.BroadcastConnectionsLimit { | |||
break | |||
} | |||
if peer == request.except { | |||
if Peer(peer) == request.except { |
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.
This comparison still works right? I forgot we are just doing pointer comparison for except.
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.
I did a standalone test but happy to write a unit test for this.
Summary
There is a race between pubsub new peer discovery and wsPeer registration:
Suggested fix is to use
gsPeer
temporary type good enough for tx handler.Additional fixes:
Test Plan
Added a test confirming
txTopicValidator
does not call tx handler with an empty wsPeer.