Skip to content

Commit

Permalink
MPX-59 - Fix MQTT over WS context cancellation (#61)
Browse files Browse the repository at this point in the history
* Upgraded the context in http handler

Signed-off-by: nyagamunene <[email protected]>

* Created new context for pass function

Signed-off-by: nyagamunene <[email protected]>

* Commented on the new changes

Signed-off-by: nyagamunene <[email protected]>

* Added more commit messages

Signed-off-by: nyagamunene <[email protected]>

---------

Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene authored and dborovcanin committed Apr 23, 2024
1 parent 0e4992b commit b69aa82
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/mqtt/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,15 @@ func (p Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

go p.pass(r.Context(), cconn)
go p.pass(cconn)
}

func (p Proxy) pass(ctx context.Context, in *websocket.Conn) {
func (p Proxy) pass(in *websocket.Conn) {
defer in.Close()

// Using a new context so as to avoiding infinitely long traces.
// And also avoiding proxy cancellation due to parent context cancellation.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
dialer := &websocket.Dialer{
Subprotocols: []string{"mqtt"},
}
Expand Down

0 comments on commit b69aa82

Please sign in to comment.