From 49f1b7aa1442225c5f48e44aa79e6fa8dbfc36a1 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Thu, 4 Jul 2024 15:29:15 +0000 Subject: [PATCH] Set read limit to 16 KB Signed-off-by: Gabriel Adrian Samfira --- websocket/client.go | 2 +- websocket/util.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/websocket/client.go b/websocket/client.go index fdccd8a5..c82f244d 100644 --- a/websocket/client.go +++ b/websocket/client.go @@ -29,7 +29,7 @@ const ( pingPeriod = (pongWait * 9) / 10 // Maximum message size allowed from peer. - maxMessageSize = 1024 + maxMessageSize = 16384 // 16 KB ) type HandleWebsocketMessage func([]byte) error diff --git a/websocket/util.go b/websocket/util.go index bd0ad6de..bb173014 100644 --- a/websocket/util.go +++ b/websocket/util.go @@ -113,8 +113,11 @@ func (w *Reader) Start() error { func (w *Reader) printWebsocketToConsole() { defer w.Stop() + w.writeMux.Lock() + w.conn.SetReadLimit(maxMessageSize) w.conn.SetReadDeadline(time.Now().Add(pongWait)) w.conn.SetPongHandler(func(string) error { w.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil }) + w.writeMux.Unlock() for { _, message, err := w.conn.ReadMessage() if err != nil {