Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpcclient: fix race condition in
doDisconnect
In this commit, we fix the following race condition: ``` ================== WARNING: DATA RACE Write at 0x00c000216018 by goroutine 31: github.com/btcsuite/btcd/rpcclient.(*Client).wsReconnectHandler() /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:736 +0x2aa github.com/btcsuite/btcd/rpcclient.New·dwrap·13() /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1496 +0x39 Previous read at 0x00c000216018 by goroutine 29: github.com/btcsuite/btcd/rpcclient.(*Client).doDisconnect() /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1079 +0x247 github.com/btcsuite/btcd/rpcclient.(*Client).Disconnect() /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1111 +0x47 github.com/btcsuite/btcd/rpcclient.(*Client).wsInHandler() /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:491 +0x1eb github.com/btcsuite/btcd/rpcclient.(*Client).start·dwrap·11() /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1181 +0x39 Goroutine 31 (running) created at: github.com/btcsuite/btcd/rpcclient.New() /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1496 +0xd77 github.com/btcsuite/btcd/rpcclient.makeClient() /home/runner/work/btcd/btcd/rpcclient/chain_test.go:268 +0x1f9 github.com/btcsuite/btcd/rpcclient.TestClientConnectedToWSServerRunner.func2() /home/runner/work/btcd/btcd/rpcclient/chain_test.go:164 +0x47 testing.tRunner() /opt/hostedtoolcache/go/1.17.5/x64/src/testing/testing.go:1259 +0x22f testing.(*T).Run·dwrap·21() /opt/hostedtoolcache/go/1.17.5/x64/src/testing/testing.go:1306 +0x47 Goroutine 29 (finished) created at: github.com/btcsuite/btcd/rpcclient.(*Client).start() /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1181 +0x2e4 github.com/btcsuite/btcd/rpcclient.New() /home/runner/work/btcd/btcd/rpcclient/infrastructure.go:1493 +0xc51 github.com/btcsuite/btcd/rpcclient.makeClient() /home/runner/work/btcd/btcd/rpcclient/chain_test.go:268 +0x1f9 github.com/btcsuite/btcd/rpcclient.TestClientConnectedToWSServerRunner.func2() /home/runner/work/btcd/btcd/rpcclient/chain_test.go:164 +0x47 testing.tRunner() /opt/hostedtoolcache/go/1.17.5/x64/src/testing/testing.go:1259 +0x22f testing.(*T).Run·dwrap·21() /opt/hostedtoolcache/go/1.17.5/x64/src/testing/testing.go:1306 +0x47 ``` This arises as in `wsReconnectHandler`, the mutex isn't held while the `conn` pointer is modified.
- Loading branch information