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

ReceiverLoop doesn't stop on cancelling context #239

Closed
srikanthccv opened this issue Jan 13, 2024 · 0 comments · Fixed by #240
Closed

ReceiverLoop doesn't stop on cancelling context #239

srikanthccv opened this issue Jan 13, 2024 · 0 comments · Fixed by #240

Comments

@srikanthccv
Copy link
Member

// ReceiverLoop runs the receiver loop. To stop the receiver cancel the context.
func (r *wsReceiver) ReceiverLoop(ctx context.Context) {
runContext, cancelFunc := context.WithCancel(ctx)
out:
for {
var message protobufs.ServerToAgent
if err := r.receiveMessage(&message); err != nil {
if ctx.Err() == nil && !websocket.IsCloseError(err, websocket.CloseNormalClosure) {
r.logger.Errorf("Unexpected error while receiving: %v", err)
}
break out
} else {
r.processor.ProcessReceivedMessage(runContext, &message)
}
}
cancelFunc()
}

The receiver loop here doesn't stop when the context is cancelled. The break out is reached only when there is an error from receiveMessage.

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 a pull request may close this issue.

1 participant