From 87552ddca789a1becc55b6df23060e0b89311b02 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 30 Aug 2023 18:45:39 +0800 Subject: [PATCH 1/4] gitignore: ignore vim files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index a92c3ab39d..460a711bc9 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ coverage.txt btcec/coverage.txt btcutil/coverage.txt btcutil/psbt/coverage.txt + +# vim +*.swp From d4f519f5dc05db026882c0597e30eb728df66ddc Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 30 Aug 2023 18:46:48 +0800 Subject: [PATCH 2/4] gomod: clean go mod files Resulted from running `go mod tify`. --- btcutil/go.sum | 1 + 1 file changed, 1 insertion(+) diff --git a/btcutil/go.sum b/btcutil/go.sum index 8d35bdaf86..58e469abe6 100644 --- a/btcutil/go.sum +++ b/btcutil/go.sum @@ -60,6 +60,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= From d62d537fb55341c772f8214c2d8a91f147caa44e Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 30 Aug 2023 20:42:16 +0800 Subject: [PATCH 3/4] rpcclient: remove redundant params used in `handleSendPostMessage` --- rpcclient/infrastructure.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index fbc43a4568..ef29b826f0 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -761,9 +761,7 @@ out: // handleSendPostMessage handles performing the passed HTTP request, reading the // result, unmarshalling it, and delivering the unmarshalled result to the // provided response channel. -func (c *Client) handleSendPostMessage(jReq *jsonRequest, - shutdown chan struct{}) { - +func (c *Client) handleSendPostMessage(jReq *jsonRequest) { protocol := "http" if !c.config.DisableTLS { protocol = "https" @@ -825,7 +823,7 @@ func (c *Client) handleSendPostMessage(jReq *jsonRequest, select { case <-time.After(backoff): - case <-shutdown: + case <-c.shutdown: return } } @@ -893,7 +891,7 @@ out: // is closed. select { case jReq := <-c.sendPostChan: - c.handleSendPostMessage(jReq, c.shutdown) + c.handleSendPostMessage(jReq) case <-c.shutdown: break out @@ -917,7 +915,6 @@ cleanup: } c.wg.Done() log.Tracef("RPC client send handler done for %s", c.config.Host) - } // sendPostRequest sends the passed HTTP request to the RPC server using the From 3a8b851aaf728a2717e422a2bb78c3f45ff88166 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 31 Aug 2023 16:54:23 +0800 Subject: [PATCH 4/4] rpcclient: catch shutdown signal when sending requests --- rpcclient/infrastructure.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index ef29b826f0..7192a171e7 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -928,9 +928,13 @@ func (c *Client) sendPostRequest(jReq *jsonRequest) { default: } - log.Tracef("Sending command [%s] with id %d", jReq.method, jReq.id) + select { + case c.sendPostChan <- jReq: + log.Tracef("Sent command [%s] with id %d", jReq.method, jReq.id) - c.sendPostChan <- jReq + case <-c.shutdown: + return + } } // newFutureError returns a new future result channel that already has the