add a defer/recover to scws WriteJson

This commit is contained in:
sawka 2023-11-10 13:36:37 -08:00
parent 5327258287
commit 7da7d06f09

View File

@ -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()