-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add nil handling on trigger subscriber+publisher #13985
Add nil handling on trigger subscriber+publisher #13985
Conversation
Do we really have cases in which the message will be nil? @cedric-cordenier |
@@ -72,6 +73,10 @@ func (p *triggerPublisher) Start(ctx context.Context) error { | |||
} | |||
|
|||
func (p *triggerPublisher) Receive(_ context.Context, msg *types.MessageBody) { | |||
if msg == nil { |
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.
@vyzaldysanchez Could we instead fix this category of error in the dispatcher, rather than each receiver? (There are currently 4 receivers and this only fixes 2 cases, and there will be more in the future)
I see two options: 1) passing in a types.MessageBody value (not a pointer) or 2) just checking for nil before sending it on the receiver channel in the dispatcher.
Probably 1 is best, wdyt @bolekk ?
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 fix I'm talking about would be done in this block here:
body, err := ValidateMessage(msg, d.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.
target/client.go and target/server.go are indeed also affected
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 getting this warning message in the IDE when trying to remove the pointer from the Receive()
definitions and calls: 'Receive' passes a lock by the value: type 'types.MessageBody' contains 'protoimpl.MessageState' contains 'sync.Mutex' which is 'sync.Locker'
.
Just sharing in case is important to note. It suggests using a pointer instead of just passing the value due to the lock copy that happens.
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.
Ah I overlooked that it was a proto -- in that case I'd just put the nil check in the caller
Quality Gate passedIssues Measures |
@@ -4,7 +4,7 @@ import ( | |||
"context" | |||
"errors" | |||
"fmt" | |||
sync "sync" |
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.
how did this happen? :|
@@ -114,7 +114,11 @@ func (d *dispatcher) SetReceiver(capabilityId string, donId uint32, rec remotety | |||
case <-ctx.Done(): | |||
return | |||
case msg := <-receiverCh: | |||
rec.Receive(ctx, msg) | |||
if msg != nil { |
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 can't be nil because ValidateMessage() never returns nil... Do we need this PR at all?
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.
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.
You are right, I'll close this PR.
Requires Dependencies
Resolves Dependencies