Skip to content

Commit 75941bf

Browse files
Fix NPE when canceling workflow without run id (#1150)
1 parent 6122fec commit 75941bf

File tree

5 files changed

+42
-10
lines changed

5 files changed

+42
-10
lines changed

internal/compatibility/proto/decision.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func Decision(d *shared.Decision) *apiv1.Decision {
108108
decision.Attributes = &apiv1.Decision_RequestCancelExternalWorkflowExecutionDecisionAttributes{
109109
RequestCancelExternalWorkflowExecutionDecisionAttributes: &apiv1.RequestCancelExternalWorkflowExecutionDecisionAttributes{
110110
Domain: attr.GetDomain(),
111-
WorkflowExecution: WorkflowRunPair(attr.WorkflowId, attr.RunId),
111+
WorkflowExecution: WorkflowRunPair(attr.GetWorkflowId(), attr.GetRunId()),
112112
Control: attr.Control,
113113
ChildWorkflowOnly: attr.GetChildWorkflowOnly(),
114114
},

internal/compatibility/proto/request.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func RecordActivityTaskHeartbeatByIdRequest(t *shared.RecordActivityTaskHeartbea
182182
}
183183
return &apiv1.RecordActivityTaskHeartbeatByIDRequest{
184184
Domain: t.GetDomain(),
185-
WorkflowExecution: WorkflowRunPair(t.WorkflowID, t.RunID),
185+
WorkflowExecution: WorkflowRunPair(t.GetWorkflowID(), t.GetRunID()),
186186
ActivityId: t.GetActivityID(),
187187
Details: Payload(t.Details),
188188
Identity: t.GetIdentity(),
@@ -263,7 +263,7 @@ func RespondActivityTaskCanceledByIdRequest(t *shared.RespondActivityTaskCancele
263263
}
264264
return &apiv1.RespondActivityTaskCanceledByIDRequest{
265265
Domain: t.GetDomain(),
266-
WorkflowExecution: WorkflowRunPair(t.WorkflowID, t.RunID),
266+
WorkflowExecution: WorkflowRunPair(t.GetWorkflowID(), t.GetRunID()),
267267
ActivityId: t.GetActivityID(),
268268
Details: Payload(t.Details),
269269
Identity: t.GetIdentity(),
@@ -287,7 +287,7 @@ func RespondActivityTaskCompletedByIdRequest(t *shared.RespondActivityTaskComple
287287
}
288288
return &apiv1.RespondActivityTaskCompletedByIDRequest{
289289
Domain: t.GetDomain(),
290-
WorkflowExecution: WorkflowRunPair(t.WorkflowID, t.RunID),
290+
WorkflowExecution: WorkflowRunPair(t.GetWorkflowID(), t.GetRunID()),
291291
ActivityId: t.GetActivityID(),
292292
Result: Payload(t.Result),
293293
Identity: t.GetIdentity(),
@@ -311,7 +311,7 @@ func RespondActivityTaskFailedByIdRequest(t *shared.RespondActivityTaskFailedByI
311311
}
312312
return &apiv1.RespondActivityTaskFailedByIDRequest{
313313
Domain: t.GetDomain(),
314-
WorkflowExecution: WorkflowRunPair(t.WorkflowID, t.RunID),
314+
WorkflowExecution: WorkflowRunPair(t.GetWorkflowID(), t.GetRunID()),
315315
ActivityId: t.GetActivityID(),
316316
Failure: Failure(t.Reason, t.Details),
317317
Identity: t.GetIdentity(),

internal/compatibility/proto/types.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ func WorkflowExecution(t *shared.WorkflowExecution) *apiv1.WorkflowExecution {
5757
}
5858
}
5959

60-
func WorkflowRunPair(workflowId, runId *string) *apiv1.WorkflowExecution {
61-
if workflowId == nil && runId == nil {
60+
func WorkflowRunPair(workflowId, runId string) *apiv1.WorkflowExecution {
61+
if workflowId == "" && runId == "" {
6262
return nil
6363
}
6464
return &apiv1.WorkflowExecution{
65-
WorkflowId: *workflowId,
66-
RunId: *runId,
65+
WorkflowId: workflowId,
66+
RunId: runId,
6767
}
6868
}
6969

@@ -471,7 +471,7 @@ func PendingChildExecutionInfo(t *shared.PendingChildExecutionInfo) *apiv1.Pendi
471471
return nil
472472
}
473473
return &apiv1.PendingChildExecutionInfo{
474-
WorkflowExecution: WorkflowRunPair(t.WorkflowID, t.RunID),
474+
WorkflowExecution: WorkflowRunPair(t.GetWorkflowID(), t.GetRunID()),
475475
WorkflowTypeName: t.GetWorkflowTypName(),
476476
InitiatedId: t.GetInitiatedID(),
477477
ParentClosePolicy: ParentClosePolicy(t.ParentClosePolicy),

test/integration_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,15 @@ func (ts *IntegrationTestSuite) TestChildWFWithParentClosePolicyAbandon() {
433433
ts.True(resp.WorkflowExecutionInfo.GetCloseTime() == 0)
434434
}
435435

436+
func (ts *IntegrationTestSuite) TestChildWFCancel() {
437+
var childWorkflowID string
438+
err := ts.executeWorkflow("test-childwf-cancel", ts.workflows.ChildWorkflowCancel, &childWorkflowID)
439+
ts.NoError(err)
440+
resp, err := ts.libClient.DescribeWorkflowExecution(context.Background(), childWorkflowID, "")
441+
ts.NoError(err)
442+
ts.Equal(shared.WorkflowExecutionCloseStatusCanceled, resp.WorkflowExecutionInfo.GetCloseStatus())
443+
}
444+
436445
func (ts *IntegrationTestSuite) TestActivityCancelUsingReplay() {
437446
replayer := worker.NewWorkflowReplayer()
438447
replayer.RegisterWorkflowWithOptions(ts.workflows.ActivityCancelRepro, workflow.RegisterOptions{DisableAlreadyRegisteredCheck: true})

test/workflow_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,28 @@ func (w *Workflows) ChildWorkflowSuccessWithParentClosePolicyAbandon(ctx workflo
355355
return childWE.ID, err
356356
}
357357

358+
func (w *Workflows) ChildWorkflowCancel(ctx workflow.Context) (result string, err error) {
359+
opts := workflow.ChildWorkflowOptions{
360+
TaskStartToCloseTimeout: 5 * time.Second,
361+
ExecutionStartToCloseTimeout: 30 * time.Second,
362+
}
363+
childCtx := workflow.WithChildOptions(ctx, opts)
364+
childCtx, cancel := workflow.WithCancel(childCtx)
365+
ft := workflow.ExecuteChildWorkflow(childCtx, w.sleep, 20*time.Second)
366+
err = workflow.Sleep(ctx, time.Second)
367+
if err != nil {
368+
return "", err
369+
}
370+
cancel()
371+
err = workflow.Sleep(ctx, time.Second)
372+
if err != nil {
373+
return "", err
374+
}
375+
var childWE internal.WorkflowExecution
376+
err = ft.GetChildWorkflowExecution().Get(ctx, &childWE)
377+
return childWE.ID, err
378+
}
379+
358380
func (w *Workflows) ActivityCancelRepro(ctx workflow.Context) ([]string, error) {
359381
ctx, cancelFunc := workflow.WithCancel(ctx)
360382

@@ -567,6 +589,7 @@ func (w *Workflows) register(worker worker.Worker) {
567589
worker.RegisterWorkflow(w.ChildWorkflowSuccess)
568590
worker.RegisterWorkflow(w.ChildWorkflowSuccessWithParentClosePolicyTerminate)
569591
worker.RegisterWorkflow(w.ChildWorkflowSuccessWithParentClosePolicyAbandon)
592+
worker.RegisterWorkflow(w.ChildWorkflowCancel)
570593
worker.RegisterWorkflow(w.InspectActivityInfo)
571594
worker.RegisterWorkflow(w.InspectLocalActivityInfo)
572595
worker.RegisterWorkflow(w.sleep)

0 commit comments

Comments
 (0)