From 0a324361546fe25aab0c34cf523f219400a634f1 Mon Sep 17 00:00:00 2001 From: Matheus Degiovani Date: Thu, 15 Aug 2024 15:30:15 -0300 Subject: [PATCH] transport: Test for released messages earlier 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. --- rpc/transport/transport.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rpc/transport/transport.go b/rpc/transport/transport.go index bdb90844..31a36563 100644 --- a/rpc/transport/transport.go +++ b/rpc/transport/transport.go @@ -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() } @@ -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() }