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

gossip: remove race on client peer id #122440

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions pkg/gossip/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ import (
type client struct {
log.AmbientContext

createdAt time.Time
peerID roachpb.NodeID // Peer node ID; 0 until first gossip response
createdAt time.Time
// peerID is the node ID of the peer we're connected to. This is set when we
// receive a response from the peer. The gossip mu should be held when
// accessing.
peerID roachpb.NodeID
resolvedPlaceholder bool // Whether we've resolved the nodeSet's placeholder for this client
addr net.Addr // Peer node network address
forwardAddr *util.UnresolvedAddr // Set if disconnected with an alternate addr
Expand Down Expand Up @@ -129,7 +132,7 @@ func (c *client) startLocked(
defer g.mu.RUnlock()
return c.peerID, c.addr
}()
if c.peerID != 0 {
if peerID != 0 {
log.Infof(ctx, "closing client to n%d (%s): %s", peerID, addr, err)
} else {
log.Infof(ctx, "closing client to %s: %s", addr, err)
Expand Down Expand Up @@ -315,8 +318,6 @@ func (c *client) gossip(
defer wg.Done()

errCh <- func() error {
var peerID roachpb.NodeID

initCh := initCh
for init := true; ; init = false {
reply, err := stream.Recv()
Expand All @@ -329,9 +330,6 @@ func (c *client) gossip(
if init {
initCh <- struct{}{}
}
if peerID == 0 && c.peerID != 0 {
peerID = c.peerID
}
}
}()
}); err != nil {
Expand Down
Loading