From a98ac0d0506839aeff7f636bbfaa5bea1cb80ddf Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 8 Feb 2026 10:59:51 -0300 Subject: [PATCH] khatru: only kill connection once. --- khatru/handlers.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/khatru/handlers.go b/khatru/handlers.go index 2cade5c..2333252 100644 --- a/khatru/handlers.go +++ b/khatru/handlers.go @@ -108,17 +108,20 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) { ), ) + killOnce := sync.Once{} kill := func() { - if nil != rl.OnDisconnect { - rl.OnDisconnect(ctx) - } + killOnce.Do(func() { + if nil != rl.OnDisconnect { + rl.OnDisconnect(ctx) + } - ticker.Stop() - cancel() - ws.cancel() - ws.conn.Close() + ticker.Stop() + cancel() + ws.cancel() + ws.conn.Close() - rl.removeClientAndListeners(ws) + rl.removeClientAndListeners(ws) + }) } go func() {