From 371cecdb849875dc40c2d21eb0bd085814c5c30a Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Fri, 3 Apr 2026 12:30:06 -0300 Subject: [PATCH] guard against nil connections on write to protect against concurrent listener removals. --- khatru/websocket.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/khatru/websocket.go b/khatru/websocket.go index c5b984e..40484c6 100644 --- a/khatru/websocket.go +++ b/khatru/websocket.go @@ -2,6 +2,7 @@ package khatru import ( "context" + "fmt" "net/http" "sync" @@ -31,6 +32,9 @@ type WebSocket struct { } func (ws *WebSocket) WriteJSON(any any) error { + if ws == nil { + return fmt.Errorf("connection doesn't exist") + } ws.mutex.Lock() err := ws.conn.WriteJSON(any) ws.mutex.Unlock()