mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-23 17:47:24 +00:00
Only close websocket disconnected chan if still open.
A channel cannot be closed multiple times, so use a select statement to only close the channel if it can not be read from.
This commit is contained in:
parent
86600a0356
commit
d8227c2751
1 changed files with 24 additions and 5 deletions
|
@ -567,7 +567,14 @@ func (s *rpcServer) walletReqsNotifications(ws *websocket.Conn) {
|
||||||
default:
|
default:
|
||||||
var m []byte
|
var m []byte
|
||||||
if err := websocket.Message.Receive(ws, &m); err != nil {
|
if err := websocket.Message.Receive(ws, &m); err != nil {
|
||||||
|
// Only close disconnected if not closed yet.
|
||||||
|
select {
|
||||||
|
case <-disconnected:
|
||||||
|
// nothing
|
||||||
|
|
||||||
|
default:
|
||||||
close(disconnected)
|
close(disconnected)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
msgs <- m
|
msgs <- m
|
||||||
|
@ -607,8 +614,14 @@ func (s *rpcServer) walletReqsNotifications(ws *websocket.Conn) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := websocket.Message.Send(ws, mresp); err != nil {
|
if err := websocket.Message.Send(ws, mresp); err != nil {
|
||||||
// Wallet disconnected.
|
// Only close disconnected if not closed yet.
|
||||||
|
select {
|
||||||
|
case <-disconnected:
|
||||||
|
// nothing
|
||||||
|
|
||||||
|
default:
|
||||||
close(disconnected)
|
close(disconnected)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,8 +633,14 @@ func (s *rpcServer) walletReqsNotifications(ws *websocket.Conn) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := websocket.Message.Send(ws, mntfn); err != nil {
|
if err := websocket.Message.Send(ws, mntfn); err != nil {
|
||||||
// Wallet disconnected.
|
// Only close disconnected if not closed yet.
|
||||||
|
select {
|
||||||
|
case <-disconnected:
|
||||||
|
// nothing
|
||||||
|
|
||||||
|
default:
|
||||||
close(disconnected)
|
close(disconnected)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue