Skip to content

Commit 6f8ced2

Browse files
committed
fix double wf registration w/ custom name bug
1 parent d8fb46a commit 6f8ced2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

dbos/workflow.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,12 @@ func registerWorkflow(ctx DBOSContext, workflowFQN string, fn WrappedWorkflowFun
246246
}
247247

248248
// We need to get a mapping from custom name to FQN for registry lookups that might not know the FQN (queue, recovery)
249+
// We also panic if we found the name was already registered (this could happen if registering two different workflows under the same custom name)
249250
if len(customName) > 0 {
250-
c.workflowCustomNametoFQN.Store(customName, workflowFQN)
251+
if _, exists := c.workflowCustomNametoFQN.LoadOrStore(customName, workflowFQN); exists {
252+
c.logger.Error("workflow function already registered", "custom_name", customName)
253+
panic(newConflictingRegistrationError(customName))
254+
}
251255
} else {
252256
c.workflowCustomNametoFQN.Store(workflowFQN, workflowFQN) // Store the FQN as the custom name if none was provided
253257
}

dbos/workflows_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,24 @@ func TestWorkflowsRegistration(t *testing.T) {
327327
RegisterWorkflow(freshCtx, simpleWorkflow, WithWorkflowName("custom-workflow"))
328328
})
329329

330+
t.Run("DifferentWorkflowsSameCustomName", func(t *testing.T) {
331+
// Create a fresh DBOS context for this test
332+
freshCtx := setupDBOS(t, false, false) // Don't check for leaks and don't reset DB
333+
334+
// First registration with custom name should work
335+
RegisterWorkflow(freshCtx, simpleWorkflow, WithWorkflowName("same-name"))
336+
337+
// Second registration of different workflow with same custom name should panic with ConflictingRegistrationError
338+
defer func() {
339+
r := recover()
340+
require.NotNil(t, r, "expected panic from registering different workflows with same custom name but got none")
341+
dbosErr, ok := r.(*DBOSError)
342+
require.True(t, ok, "expected panic to be *DBOSError, got %T", r)
343+
assert.Equal(t, ConflictingRegistrationError, dbosErr.Code)
344+
}()
345+
RegisterWorkflow(freshCtx, simpleWorkflowError, WithWorkflowName("same-name"))
346+
})
347+
330348
t.Run("RegisterAfterLaunchPanics", func(t *testing.T) {
331349
// Create a fresh DBOS context for this test
332350
freshCtx := setupDBOS(t, false, false) // Don't check for leaks and don't reset DB

0 commit comments

Comments
 (0)