diff --git a/rpcserver.go b/rpcserver.go index 6450b1363..5247c97f4 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -147,7 +147,10 @@ func (s *rpcServer) Start() { w.Header().Set("Connection", "close") jsonRPCRead(w, r, s) }) + + s.wg.Add(1) go s.walletListenerDuplicator() + rpcServeMux.HandleFunc("/wallet", func(w http.ResponseWriter, r *http.Request) { if err := s.checkAuth(r); err != nil { http.Error(w, "401 Unauthorized.", http.StatusUnauthorized) @@ -203,9 +206,9 @@ func (s *rpcServer) Stop() error { return err } } - rpcsLog.Infof("RPC server shutdown complete") - s.wg.Wait() close(s.quit) + s.wg.Wait() + rpcsLog.Infof("RPC server shutdown complete") return nil } diff --git a/rpcwebsocket.go b/rpcwebsocket.go index 1f3e2a91e..5d714c6cc 100644 --- a/rpcwebsocket.go +++ b/rpcwebsocket.go @@ -367,7 +367,7 @@ func handleRescan(s *rpcServer, icmd btcjson.Cmd, c handlerChans) (interface{}, // client requesting the rescan has disconnected. select { case <-c.disconnected: - rpcsLog.Infof("Stopping rescan at height %v for disconnected client", + rpcsLog.Debugf("Stopping rescan at height %v for disconnected client", blk.Height()) return nil, nil @@ -518,6 +518,7 @@ func (s *rpcServer) RemoveWalletListener(n ntfnChan) { func (s *rpcServer) walletListenerDuplicator() { // Duplicate all messages sent across walletNotificationMaster to each // listening wallet. +out: for { select { case ntfn := <-s.ws.walletNotificationMaster: @@ -528,9 +529,11 @@ func (s *rpcServer) walletListenerDuplicator() { s.ws.RUnlock() case <-s.quit: - return + break out } } + + s.wg.Done() } // walletReqsNotifications is the handler function for websocket @@ -587,7 +590,13 @@ func (s *rpcServer) walletReqsNotifications(ws *websocket.Conn) { case <-s.quit: // Server closed. Closing disconnected signals handlers to stop // and flushes all channels handlers may write to. - close(disconnected) + select { + case <-disconnected: + // nothing + + default: + close(disconnected) + } case <-disconnected: for {