From 0d0b416146dd146a5dcfbf61f09f8136aa5afdc2 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 31 May 2023 21:27:38 +0200 Subject: create websocket context after successfully identifying the connection Fixes: d8bdce51c336f3693121202402ee38ff3f12c0e2 --- main.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 53dc440..8ff3a81 100644 --- a/main.go +++ b/main.go @@ -201,10 +201,6 @@ func wsEndpoint(w http.ResponseWriter, r *http.Request) { return } - ctx, cancel := context.WithCancel(r.Context()) - - ctx = c.CloseRead(ctx) - uuidCookie, err := r.Cookie("UUID") if err != nil { llog.Error("websocket connection has no set UUID cookie") @@ -219,6 +215,9 @@ func wsEndpoint(w http.ResponseWriter, r *http.Request) { return } + ctx, cancel := context.WithCancel(r.Context()) + ctx = c.CloseRead(ctx) + defer func() { llog.Info("cancel context of connection %v", id) cancel() -- cgit v1.2.3