From 815c2730e21a74595c9109ff14198d650fa09929 Mon Sep 17 00:00:00 2001 From: Mayank Raj Date: Mon, 26 Oct 2026 12:43:45 +0530 Subject: [PATCH] docs(wsjson): document that Read closes the connection on bad JSON Read closes the connection with StatusInvalidFramePayloadData when the message cannot be unmarshalled, but its doc comment did not say so. Callers that retry in a loop then spin on a closed connection. State the behavior and point to c.Read plus json.Unmarshal for callers that want to keep the connection open. --- wsjson/wsjson.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wsjson/wsjson.go b/wsjson/wsjson.go index ffa068bf..b29212bc 100644 --- a/wsjson/wsjson.go +++ b/wsjson/wsjson.go @@ -14,6 +14,11 @@ import ( // Read reads a JSON message from c into v. // It will reuse buffers in between calls to avoid allocations. +// +// If the message cannot be unmarshalled into v, Read closes the connection +// with websocket.StatusInvalidFramePayloadData and returns an error wrapping +// the unmarshal error. To keep the connection open on bad JSON, read the +// message with c.Read and call json.Unmarshal yourself. func Read(ctx context.Context, c *websocket.Conn, v any) error { return read(ctx, c, v) }