Skip to content

Commit 3c264de

Browse files
committed
fix: don't panic on short errors
1 parent 00a60b3 commit 3c264de

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

proxy/websocket.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,15 @@ func (p *Websocket) closeWebsocket(conn *websocket.Conn, reason error) error {
392392
)
393393
}
394394

395+
msg := []byte(reason.Error())
396+
if len(msg) > 125 {
397+
// maxControlFramePayloadSize == 125
398+
msg = msg[:125]
399+
}
400+
395401
return errors.Join(
396402
conn.WriteControl(
397-
// maxControlFramePayloadSize == 125
398-
websocket.CloseMessage, []byte(reason.Error())[:125], utils.Deadline(p.cfg.proxy.ControlTimeout),
403+
websocket.CloseMessage, msg, utils.Deadline(p.cfg.proxy.ControlTimeout),
399404
),
400405
conn.Close(),
401406
)

0 commit comments

Comments
 (0)