From 7da7d06f090fad995c738135e2360390bd37b53f Mon Sep 17 00:00:00 2001 From: sawka Date: Fri, 10 Nov 2023 13:36:37 -0800 Subject: [PATCH] add a defer/recover to scws WriteJson --- wavesrv/pkg/scws/scws.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/wavesrv/pkg/scws/scws.go b/wavesrv/pkg/scws/scws.go index 25cad69f..4d0b30ad 100644 --- a/wavesrv/pkg/scws/scws.go +++ b/wavesrv/pkg/scws/scws.go @@ -128,11 +128,23 @@ func (ws *WSState) RunUpdates(updateCh chan interface{}) { for update := range updateCh { shell := ws.GetShell() if shell != nil { - shell.WriteJson(update) + writeJsonProtected(shell, update) } } } +func writeJsonProtected(shell *wsshell.WSShell, update any) { + defer func() { + r := recover() + if r == nil { + return + } + log.Printf("[error] in scws RunUpdates WriteJson: %v\n", r) + return + }() + shell.WriteJson(update) +} + func (ws *WSState) ReplaceShell(shell *wsshell.WSShell) { ws.Lock.Lock() defer ws.Lock.Unlock()