From 7efb3409cfcc1d9c0d24d68f722d9ba846d59470 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Fri, 15 Nov 2024 15:10:52 -0500 Subject: [PATCH] fix: unlock mutex if trying is successful Signed-off-by: Donnie Adams --- run.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/run.go b/run.go index 2ed6c1c..dac9c15 100644 --- a/run.go +++ b/run.go @@ -135,10 +135,13 @@ func (r *Run) Close() error { return fmt.Errorf("run not started") } - if !r.lock.TryLock() { - // If we can't get the lock, then the run is still running. Abort it. - r.cancel(errAbortRun) + if r.lock.TryLock() { + r.lock.Unlock() + // If we can get the lock, then the run isn't running, so nothing to do. + return nil } + + r.cancel(errAbortRun) if r.wait == nil { return nil }