Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Mutex not being released on step completion #4847

Merged
merged 7 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,9 @@ func (woc *wfOperationCtx) executeTemplate(nodeName string, orgTmpl wfv1.Templat
woc.computeMetrics(processedTmpl.Metrics.Prometheus, localScope, realTimeScope, false)
}
}
if processedTmpl.Synchronization != nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node status will be calculated here for retry nodes. The lock has to be released if the node is fulfilled

woc.controller.syncManager.Release(woc.wf, node.ID, processedTmpl.Synchronization)
}
return retryParentNode, nil
}
lastChildNode := getChildNodeIndex(retryParentNode, woc.wf.Status.Nodes, -1)
Expand Down
83 changes: 83 additions & 0 deletions workflow/controller/operator_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,86 @@ func TestMutexInDAG(t *testing.T) {
}
})
}

const RetryWfWithSemaphore = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: script-wf
namespace: default
spec:
entrypoint: step1
retryStrategy:
limit: 10
templates:
- name: step1
steps:
- - name: hello1
template: whalesay
- - name: hello2
template: whalesay
- name: whalesay
daemon: true
synchronization:
semaphore:
configMapKeyRef:
key: template
name: my-config
container:
args:
- "hello world"
command:
- cowsay
image: "docker/whalesay:latest"
`

func TestSynchronizationWithRetry(t *testing.T) {
assert := assert.New(t)
cancel, controller := newController()
defer cancel()
controller.syncManager = sync.NewLockManager(GetSyncLimitFunc(controller.kubeclientset), func(key string) {
})
var cm v1.ConfigMap
err := yaml.Unmarshal([]byte(configMap), &cm)
assert.NoError(err)
_, err = controller.kubeclientset.CoreV1().ConfigMaps("default").Create(&cm)
assert.NoError(err)
t.Run("WorkflowWithRetry", func(t *testing.T) {
wf := unmarshalWF(RetryWfWithSemaphore)
wf, err := controller.wfclientset.ArgoprojV1alpha1().Workflows(wf.Namespace).Create(wf)
assert.NoError(err)
woc := newWorkflowOperationCtx(wf, controller)
woc.operate()
for _, node := range woc.wf.Status.Nodes {
if node.Name == "hello1" {
assert.Equal(wfv1.NodePending, node.Phase)
}
}

// Updating Pod state
makePodsPhase(woc, v1.PodSucceeded)

// Release the lock from hello1
woc = newWorkflowOperationCtx(woc.wf, controller)
woc.operate()
for _, node := range woc.wf.Status.Nodes {
if node.Name == "hello1" {
assert.Equal(wfv1.NodeSucceeded, node.Phase)
}
if node.Name == "hello2" {
assert.Equal(wfv1.NodePending, node.Phase)
}
}
// Updating Pod state
makePodsPhase(woc, v1.PodSucceeded)

// Release the lock from hello2
woc = newWorkflowOperationCtx(woc.wf, controller)
woc.operate()
// Nobody is waiting for the lock
assert.Empty(woc.wf.Status.Synchronization.Semaphore.Waiting)
// Nobody is holding the lock
assert.Empty(woc.wf.Status.Synchronization.Semaphore.Holding[0].Holders)

})
}
1 change: 1 addition & 0 deletions workflow/sync/sync_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (cm *Manager) Release(wf *wfv1.Workflow, nodeName string, syncRef *wfv1.Syn

if syncLockHolder, ok := cm.syncLockMap[lockName.EncodeName()]; ok {
syncLockHolder.release(holderKey)
syncLockHolder.removeFromQueue(holderKey)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mainly for edge cases to avoid the release node shouldn't be in pending state.

log.Debugf("%s sync lock is released by %s", lockName.EncodeName(), holderKey)
lockKey := lockName.EncodeName()
wf.Status.Synchronization.GetStatus(syncRef.GetType()).LockReleased(holderKey, lockKey)
Expand Down