From a40c4b9e1dc0eccb08fecc25bfe492362485fd8f Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 13 Apr 2021 13:39:33 -0700 Subject: [PATCH] Fix deadlock when reset occurs during cool-off period --- tor/torProvider.go | 3 ++- tor/torProvider_test.go | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tor/torProvider.go b/tor/torProvider.go index 6819a1f..2bce6d5 100644 --- a/tor/torProvider.go +++ b/tor/torProvider.go @@ -212,11 +212,12 @@ func (tp *torProvider) Restart() { log.Debugf("launching restart...") tp.lock.Lock() + defer tp.lock.Unlock() log.Debugf("checking last restart time") if time.Now().Sub(tp.lastRestartTime) < restartCooldown { return } - tp.lock.Unlock() + go tp.restart() } diff --git a/tor/torProvider_test.go b/tor/torProvider_test.go index d906c3d..dcb0e5d 100644 --- a/tor/torProvider_test.go +++ b/tor/torProvider_test.go @@ -40,5 +40,12 @@ func TestTorProvider(t *testing.T) { t.Logf("progress: %v", progress) } + // Should skip without blocking... + acn.Restart() + acn.Restart() + acn.Restart() + + + acn.Close() }