diff --git a/rpctest/rpc_harness.go b/rpctest/rpc_harness.go index 3a97b6c55..fc071b862 100644 --- a/rpctest/rpc_harness.go +++ b/rpctest/rpc_harness.go @@ -255,12 +255,11 @@ func (h *Harness) SetUp(createTestChain bool, numMatureOutputs uint32) error { return nil } -// TearDown stops the running rpc test instance. All created processes are +// tearDown stops the running rpc test instance. All created processes are // killed, and temporary directories removed. // -// NOTE: This method and SetUp should always be called from the same goroutine -// as they are not concurrent safe. -func (h *Harness) TearDown() error { +// This function MUST be called with the harness state mutex held (for writes). +func (h *Harness) tearDown() error { if h.Node != nil { h.Node.Shutdown() } @@ -278,6 +277,18 @@ func (h *Harness) TearDown() error { return nil } +// TearDown stops the running rpc test instance. All created processes are +// killed, and temporary directories removed. +// +// NOTE: This method and SetUp should always be called from the same goroutine +// as they are not concurrent safe. +func (h *Harness) TearDown() error { + harnessStateMtx.Lock() + defer harnessStateMtx.Unlock() + + return h.tearDown() +} + // connectRPCClient attempts to establish an RPC connection to the created btcd // process belonging to this Harness instance. If the initial connection // attempt fails, this function will retry h.maxConnRetries times, backing off diff --git a/rpctest/utils.go b/rpctest/utils.go index b10f462f3..50cbb9983 100644 --- a/rpctest/utils.go +++ b/rpctest/utils.go @@ -140,7 +140,7 @@ func TearDownAll() error { defer harnessStateMtx.Unlock() for _, harness := range testInstances { - if err := harness.TearDown(); err != nil { + if err := harness.tearDown(); err != nil { return err } }