Skip to content

Commit

Permalink
Improved context cancel check after websocket closure
Browse files Browse the repository at this point in the history
  • Loading branch information
kostasbalampekos committed Apr 5, 2024
1 parent 1dbc52e commit 1ca874f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/mqtt/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ func (p Proxy) handle() http.Handler {
go func() {
defer cancel() // Cancel the context when the goroutine finishes
p.pass(ctx, cconn)
if err := ctx.Err(); err != nil {
p.logger.Info("Context error at the end of goroutine", slog.Any("error", err))
} else {
select {
case <-ctx.Done():
p.logger.Info("Context cancelled at the end of goroutine", slog.Any("error", ctx.Err()))
default:
p.logger.Info("Context still active at the end of goroutine")
}
}()
Expand Down

0 comments on commit 1ca874f

Please sign in to comment.