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:
Josh Rickmar 2014-01-14 21:45:42 -05:00
parent 86600a0356
commit d8227c2751

View file

@ -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
}
}