Skip to content

Commit

Permalink
Improved with a cancelable context
Browse files Browse the repository at this point in the history
  • Loading branch information
kostasbalampekos committed Apr 5, 2024
1 parent 3ae1d1b commit 1dbc52e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/mqtt/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ func (p Proxy) handle() http.Handler {
return
}

ctx := context.Background() // Create a new context
ctx, cancel := context.WithCancel(context.Background())
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))
Expand Down

0 comments on commit 1dbc52e

Please sign in to comment.