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:
|
||||
var m []byte
|
||||
if err := websocket.Message.Receive(ws, &m); err != nil {
|
||||
close(disconnected)
|
||||
// Only close disconnected if not closed yet.
|
||||
select {
|
||||
case <-disconnected:
|
||||
// nothing
|
||||
|
||||
default:
|
||||
close(disconnected)
|
||||
}
|
||||
return
|
||||
}
|
||||
msgs <- m
|
||||
|
@ -607,8 +614,14 @@ func (s *rpcServer) walletReqsNotifications(ws *websocket.Conn) {
|
|||
continue
|
||||
}
|
||||
if err := websocket.Message.Send(ws, mresp); err != nil {
|
||||
// Wallet disconnected.
|
||||
close(disconnected)
|
||||
// Only close disconnected if not closed yet.
|
||||
select {
|
||||
case <-disconnected:
|
||||
// nothing
|
||||
|
||||
default:
|
||||
close(disconnected)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -620,8 +633,14 @@ func (s *rpcServer) walletReqsNotifications(ws *websocket.Conn) {
|
|||
continue
|
||||
}
|
||||
if err := websocket.Message.Send(ws, mntfn); err != nil {
|
||||
// Wallet disconnected.
|
||||
close(disconnected)
|
||||
// Only close disconnected if not closed yet.
|
||||
select {
|
||||
case <-disconnected:
|
||||
// nothing
|
||||
|
||||
default:
|
||||
close(disconnected)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue