Skip to content

Commit 7da7d06

Browse files
committed
add a defer/recover to scws WriteJson
1 parent 5327258 commit 7da7d06

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

wavesrv/pkg/scws/scws.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,23 @@ func (ws *WSState) RunUpdates(updateCh chan interface{}) {
128128
for update := range updateCh {
129129
shell := ws.GetShell()
130130
if shell != nil {
131-
shell.WriteJson(update)
131+
writeJsonProtected(shell, update)
132132
}
133133
}
134134
}
135135

136+
func writeJsonProtected(shell *wsshell.WSShell, update any) {
137+
defer func() {
138+
r := recover()
139+
if r == nil {
140+
return
141+
}
142+
log.Printf("[error] in scws RunUpdates WriteJson: %v\n", r)
143+
return
144+
}()
145+
shell.WriteJson(update)
146+
}
147+
136148
func (ws *WSState) ReplaceShell(shell *wsshell.WSShell) {
137149
ws.Lock.Lock()
138150
defer ws.Lock.Unlock()

0 commit comments

Comments
 (0)