Skip to content

Commit

Permalink
[CAPPL-472] Avoid overwriting engines (#15967)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier authored Jan 17, 2025
1 parent 9bc0db5 commit a5ed556
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion core/services/workflows/syncer/engine_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ func NewEngineRegistry() *EngineRegistry {
}

// Add adds an engine to the registry.
func (r *EngineRegistry) Add(id string, engine services.Service) {
func (r *EngineRegistry) Add(id string, engine services.Service) error {
r.mu.Lock()
defer r.mu.Unlock()
if _, found := r.engines[id]; found {
return errors.New("attempting to register duplicate engine")
}
r.engines[id] = engine
return nil
}

// Get retrieves an engine from the registry.
Expand Down
6 changes: 5 additions & 1 deletion core/services/workflows/syncer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,11 @@ func (h *eventHandler) workflowRegisteredEvent(
return fmt.Errorf("failed to start workflow engine: %w", err)
}

h.engineRegistry.Add(wfID, engine)
// This shouldn't happen because we call the handler serially and
// check for running engines above, see the call to engineRegistry.IsRunning.
if err := h.engineRegistry.Add(wfID, engine); err != nil {
return fmt.Errorf("invariant violation: %w", err)
}

return nil
}
Expand Down

0 comments on commit a5ed556

Please sign in to comment.