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

Add nil handling on trigger subscriber+publisher #13985

Closed

Conversation

vyzaldysanchez
Copy link
Contributor

Requires Dependencies

Resolves Dependencies

@vyzaldysanchez
Copy link
Contributor Author

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 {
Copy link
Contributor

@cedric-cordenier cedric-cordenier Aug 1, 2024

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 ?

Copy link
Contributor

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)

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

@@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
sync "sync"
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bolekk when failing to unmarshal the message it returns nil.

It can be seen in the first couple of lines here

Copy link
Contributor Author

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.

@vyzaldysanchez vyzaldysanchez requested a review from bolekk August 7, 2024 13:04
auto-merge was automatically disabled August 7, 2024 13:57

Pull request was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants