Skip to content

Commit

Permalink
Do not call mutex.Unlock() when locking failed
Browse files Browse the repository at this point in the history
  • Loading branch information
perk11 committed Feb 3, 2025
1 parent 3655c9b commit ca331f5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ func (rm ResourceManager) maybeGetRunningServiceNoLock(name string) (RunningServ

func (rm ResourceManager) maybeGetRunningService(name string) (RunningService, bool) {
if interrupted {
rm.serviceMutex.TryLock()
if rm.serviceMutex.TryLock() {
defer rm.serviceMutex.Unlock()
}
} else {
rm.serviceMutex.Lock()
defer rm.serviceMutex.Unlock()
}
defer rm.serviceMutex.Unlock()
return rm.maybeGetRunningServiceNoLock(name)
}

Expand Down

0 comments on commit ca331f5

Please # to comment.