Skip to content

Commit

Permalink
transport: Test for released messages earlier
Browse files Browse the repository at this point in the history
This moves the check for released messages earlier in the Release() call
for transport messages. This prevents triggering the race detector, due
to the check happening before an attempt is made at accessing the
message (which involves indirection through a segment that may have been
released already).

While the prior code would not have actually caused a fault in current
code (because the conditional checks both for the released flag and
whether the message is nil), checking by the release flag first is
more correct and may prevent future bugs.
  • Loading branch information
matheusd committed Aug 15, 2024
1 parent e5b07cb commit 0a32436
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions rpc/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ type outgoingMsg struct {
}

func (o *outgoingMsg) Release() {
if m := o.message.Message(); !o.released && m != nil {
if o.released {
return
}
if m := o.message.Message(); m != nil {
o.released = true
m.Release()
}
Expand Down Expand Up @@ -246,7 +249,10 @@ func (i *incomingMsg) Message() rpccp.Message {
}

func (i *incomingMsg) Release() {
if m := i.Message().Message(); !i.released && m != nil {
if i.released {
return
}
if m := i.Message().Message(); m != nil {
i.released = true
m.Release()
}
Expand Down

0 comments on commit 0a32436

Please sign in to comment.