Skip to content

Conversation

@yuandrew
Copy link
Contributor

@yuandrew yuandrew commented Jun 9, 2025

What was changed

Dispatch a new coroutine with workflow context when canceling external workflow in workflow testsuite

Why?

Fix testsuite specific error

Checklist

  1. Closes Getting a strange error when writing tests which does not occur in real temporal deployment #1961

  2. How was this tested:
    Added test


Note

When canceling the current (child) workflow via external cancel, run the cancel handler in a new dispatcher coroutine to avoid illegal access errors; add a test covering this path.

  • Testsuite behavior:
    • For RequestCancelExternalWorkflow targeting the current workflow, wrap cancel logic in cancelFunc and, if a child workflow with *syncWorkflowDefinition, dispatch it via a new coroutine on the workflow dispatcher; otherwise call directly. Ensures child-cancel flows run within workflow context.
    • Preserve child-canceled listener callback behavior.
  • Tests:
    • Add SleepHour, SleepThenCancel workflows and TestRequestCancelExternalWorkflowInSelector to validate canceling an external child workflow (timer cancel path) succeeds without "illegal access" errors.

Written by Cursor Bugbot for commit 1edd76a. This will update automatically on new commits. Configure here.

@yuandrew yuandrew requested a review from a team as a code owner June 9, 2025 15:57
@Quinn-With-Two-Ns
Copy link
Contributor

Do you know why the feature tests are failing for your PR?

@yuandrew
Copy link
Contributor Author

Seems like it was a transient issue, features tests are passing now after merging with master

env.postCallback(func() {
env.onChildWorkflowCanceledListener(env.workflowInfo)
}, false)
sd.dispatcher.NewCoroutine(sd.rootCtx, "cancel-self", true, func(ctx Context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't running the postCallback enough?

Copy link
Contributor Author

@yuandrew yuandrew Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment explaining why this would be needed, not sure it's worth a larger refactor, lmk if you think otherwise

// The way testWorkflowEnvironment is setup today, we close the child workflow dispatcher before calling
// the workflowCancelHandler. A larger refactor would be needed to handle this similar to non-test code.
// Maybe worth doing when https://github.com/temporalio/go-sdk/issues/50 is tackled.

@yuandrew yuandrew changed the title Fix canceling external workflow in Selector Fix canceling external workflows that are children in testsuite Jul 14, 2025
// the workflowCancelHandler. A larger refactor would be needed to handle this similar to non-test code.
// Maybe worth doing when https://github.com/temporalio/go-sdk/issues/50 is tackled.
if sd, ok := env.workflowDef.(*syncWorkflowDefinition); ok && env.isChildWorkflow() {
sd.dispatcher.NewCoroutine(sd.rootCtx, "cancel-self", true, func(ctx Context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this run immediately? Any compatibly concern with running this in a coroutine now and changing the sequence with onChildWorkflowCanceledListener?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good callout, the onChildWorkflowCanceledListener logic should only run during the coroutine we spawn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Getting a strange error when writing tests which does not occur in real temporal deployment

2 participants