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

Fix race in grpcsync.CallbackSerializer #6778

Closed
Closed
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
7 changes: 3 additions & 4 deletions internal/grpcsync/callback_serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ func (cs *CallbackSerializer) run(ctx context.Context) {
// Do nothing here. Next iteration of the for loop will not happen,
// since ctx.Err() would be non-nil.
case callback, ok := <-cs.callbacks.Get():
if !ok {
return
if ok {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should need to read or check ok at all here. There's no way ok can ever be false, because the channel is only closed later. We'll unblock the select only when the context is canceled or a callback is created.

cs.callbacks.Load()
callback.(func(ctx context.Context))(ctx)
}
cs.callbacks.Load()
callback.(func(ctx context.Context))(ctx)
}
}

Expand Down