Skip to content

Commit

Permalink
[fix] Race in workflow engine (#13879)
Browse files Browse the repository at this point in the history
* [fix] Fix race in workflow engine

* Remove unused mutex
  • Loading branch information
cedric-cordenier authored Jul 30, 2024
1 parent 1eaf5e0 commit c3dc764
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions core/services/workflows/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (e *Engine) registerTrigger(ctx context.Context, t *triggerCapability, trig
return err
}

t.config = tc
t.config.Store(tc)

triggerRegRequest := capabilities.CapabilityRequest{
Metadata: capabilities.RequestMetadata{
Expand All @@ -343,7 +343,7 @@ func (e *Engine) registerTrigger(ctx context.Context, t *triggerCapability, trig
WorkflowName: e.workflow.name,
WorkflowOwner: e.workflow.owner,
},
Config: tc,
Config: t.config.Load(),
Inputs: triggerInputs,
}
eventsCh, err := t.trigger.RegisterTrigger(ctx, triggerRegRequest)
Expand Down Expand Up @@ -788,7 +788,7 @@ func (e *Engine) deregisterTrigger(ctx context.Context, t *triggerCapability, tr
WorkflowOwner: e.workflow.owner,
},
Inputs: triggerInputs,
Config: t.config,
Config: t.config.Load(),
}

// if t.trigger == nil, then we haven't initialized the workflow
Expand Down
4 changes: 3 additions & 1 deletion core/services/workflows/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package workflows
import (
"errors"
"fmt"
"sync/atomic"

"github.com/dominikbraun/graph"

Expand Down Expand Up @@ -86,7 +87,8 @@ type step struct {
type triggerCapability struct {
workflows.StepDefinition
trigger capabilities.TriggerCapability
config *values.Map

config atomic.Pointer[values.Map]
}

func Parse(yamlWorkflow string) (*workflow, error) {
Expand Down

0 comments on commit c3dc764

Please sign in to comment.