Skip to content

Commit 145f109

Browse files
fix: concurrent map write for migrating schedules back to v1 (#10164)
## What changed? Some observed panics in production spotted by @yycptt were causing crashes. The mutation `searchattribute.AddSearchAttribute(&sa, sadefs.TemporalNamespaceDivision, payload.EncodeString(legacyscheduler.NamespaceDivision))` presumably intermittently was happening while another read was happening elsewhere in the system, causing a crash. ## Why? Need to avoid panics in prod ## How did you test it? - [X] built - [ ] run locally and tested manually - [X] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s) ## Potential risks Not expected to be high risk as it's just a clone, might need some more test coverage however. I am unsure if we have enough coverage to ensure there's no data drops
1 parent d74eabf commit 145f109

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

chasm/lib/scheduler/scheduler_migrate_task.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"maps"
78
"time"
89

910
"github.com/google/uuid"
@@ -152,7 +153,7 @@ func (h *SchedulerMigrateToWorkflowTaskHandler) Execute(
152153
// Build the start request to match createScheduleWorkflow in the frontend
153154
// as closely as possible. Include TemporalNamespaceDivision so the V1
154155
// workflow is discoverable via ListSchedules.
155-
sa := &commonpb.SearchAttributes{IndexedFields: result.searchAttributes}
156+
sa := &commonpb.SearchAttributes{IndexedFields: maps.Clone(result.searchAttributes)}
156157
searchattribute.AddSearchAttribute(&sa, sadefs.TemporalNamespaceDivision, payload.EncodeString(legacyscheduler.NamespaceDivision))
157158
workflowID := legacyscheduler.WorkflowIDPrefix + result.scheduleID
158159
startReq := &workflowservice.StartWorkflowExecutionRequest{
@@ -165,7 +166,7 @@ func (h *SchedulerMigrateToWorkflowTaskHandler) Execute(
165166
Identity: fmt.Sprintf("temporal-scheduler-migration-%s-%s", result.namespace, result.scheduleID),
166167
WorkflowIdReusePolicy: enumspb.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE,
167168
WorkflowIdConflictPolicy: enumspb.WORKFLOW_ID_CONFLICT_POLICY_FAIL,
168-
Memo: &commonpb.Memo{Fields: result.memo},
169+
Memo: &commonpb.Memo{Fields: maps.Clone(result.memo)},
169170
SearchAttributes: sa,
170171
Priority: &commonpb.Priority{},
171172
}

0 commit comments

Comments
 (0)