Skip to content

Commit

Permalink
Trying the context.WithouthCancel context creation for the websocket.…
Browse files Browse the repository at this point in the history
… This is a suggestion from the Mainflux team
  • Loading branch information
kostasbalampekos committed Apr 9, 2024
1 parent 21c1f56 commit b762b93
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions pkg/mqtt/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,7 @@ func (p Proxy) handle() http.Handler {
return
}

ctx, cancel := context.WithCancel(context.Background())
go func() {
defer cancel() // Cancel the context when the goroutine finishes
p.pass(ctx, cconn)
time.Sleep(5 * time.Second)
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")
}
}()
go p.pass(context.WithoutCancel(r.Context()), cconn)
})
}

Expand Down

0 comments on commit b762b93

Please sign in to comment.