Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions workflow/sync/sync_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type (

type Manager struct {
syncLockMap map[string]semaphore
lock *sync.Mutex
lock *sync.RWMutex
nextWorkflow NextWorkflow
getSyncLimit GetSyncLimit
isWFDeleted IsWorkflowDeleted
Expand All @@ -29,7 +29,7 @@ type Manager struct {
func NewLockManager(getSyncLimit GetSyncLimit, nextWorkflow NextWorkflow, isWFDeleted IsWorkflowDeleted) *Manager {
return &Manager{
syncLockMap: make(map[string]semaphore),
lock: &sync.Mutex{},
lock: &sync.RWMutex{},
nextWorkflow: nextWorkflow,
getSyncLimit: getSyncLimit,
isWFDeleted: isWFDeleted,
Expand All @@ -50,6 +50,9 @@ func (sm *Manager) getWorkflowKey(key string) (string, error) {
func (sm *Manager) CheckWorkflowExistence() {
defer runtimeutil.HandleCrash(runtimeutil.PanicHandlers...)

sm.lock.RLock()
defer sm.lock.RUnlock()

log.Debug("Check the workflow existence")
for _, lock := range sm.syncLockMap {
keys := lock.getCurrentHolders()
Expand Down Expand Up @@ -311,8 +314,8 @@ func (sm *Manager) Release(ctx context.Context, wf *wfv1.Workflow, nodeName stri
return
}

sm.lock.Lock()
defer sm.lock.Unlock()
sm.lock.RLock()
defer sm.lock.RUnlock()

holderKey := getHolderKey(wf, nodeName)
// Ignoring error here is as good as it's going to be, we shouldn't get here as we should
Expand All @@ -336,8 +339,8 @@ func (sm *Manager) Release(ctx context.Context, wf *wfv1.Workflow, nodeName stri
}

func (sm *Manager) ReleaseAll(wf *wfv1.Workflow) bool {
sm.lock.Lock()
defer sm.lock.Unlock()
sm.lock.RLock()
defer sm.lock.RUnlock()

if wf.Status.Synchronization == nil {
return true
Expand Down