From 8b5413a4acd5c2c587d4a065eb5b1022109aed0d Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 11 Nov 2013 12:49:48 -0500 Subject: [PATCH] Always release ws context reader lock. Previously, on a blockconnected notification, the websocket context reader lock was not always being given up properly. This change defers the unlock so it will always happen. This fixes an issue where wallet will stop responding (due to not being able to complete its handshake) on reconnect. --- rpcserver.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 617ec14c..0963a5a5 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1256,6 +1256,7 @@ func (s *rpcServer) websocketJSONHandler(walletNotification chan []byte, // to each connected wallet. func (s *rpcServer) NotifyBlockConnected(block *btcutil.Block) { s.ws.RLock() + defer s.ws.RUnlock() hash, err := block.Sha() if err != nil { log.Error("Bad block; connected block notification dropped.") @@ -1281,7 +1282,6 @@ func (s *rpcServer) NotifyBlockConnected(block *btcutil.Block) { } } } - s.ws.RUnlock() } // NotifyBlockDisconnected creates and marshals a JSON message to notify @@ -1366,7 +1366,8 @@ func (s *rpcServer) newBlockNotifyCheckTxIn(tx *btcutil.Tx) { // newBlockNotifyCheckTxOut is a helper function to iterate through // each transaction output of a new block and perform any checks and // notify listening frontends when necessary. -func (s *rpcServer) newBlockNotifyCheckTxOut(block *btcutil.Block, tx *btcutil.Tx) { +func (s *rpcServer) newBlockNotifyCheckTxOut(block *btcutil.Block, + tx *btcutil.Tx) { for i, txout := range tx.MsgTx().TxOut { _, txaddrhash, err := btcscript.ScriptToAddrHash(txout.PkScript)