Skip to content

Warn on unfinished handlers and provide workflow.allHandlersFinished() API #1459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dandavison
Copy link
Contributor

@dandavison dandavison commented Jul 8, 2024

Fixes #1434 and #1435.

  • new workflow API to wait for all signal and update handlers to be finished:
    await workflow.condition(() => workflow.allHandlersFinished())
  • By default, warn when workflow exits with unfinished handlers, but not when a handler finishes due to workflow cancellation or workflow failure.
  • Warnings controlled by HandlerUnfinishedPolicy

@dandavison dandavison force-pushed the 1434-warn-on-unfinished-handlers branch 9 times, most recently from 4f6f7aa to 1a48acf Compare July 15, 2024 18:25
@dandavison dandavison force-pushed the 1434-warn-on-unfinished-handlers branch 2 times, most recently from 6fd42a4 to ae386a1 Compare July 17, 2024 16:48
@dandavison dandavison marked this pull request as ready for review July 17, 2024 16:49
@dandavison dandavison requested a review from a team as a code owner July 17, 2024 16:49
@dandavison dandavison force-pushed the 1434-warn-on-unfinished-handlers branch from ae386a1 to f7cddea Compare July 17, 2024 23:15
Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

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

I'm concerned with allHandlersFinished returning true between handling of a signal and an update.

I noticed that updates aren't reordered an put in the first activation batch:

const [signals, nonSignals] = partition(nonPatches, ({ signalWorkflow }) => signalWorkflow != null);

This means that this workflow won't get a chance to see an update:

import * as workflow from '@temporalio/workflow';

const fooSignal = workflow.defineSignal('foo');
const fooUpdate = workflow.defineUpdate('foo');

export async function http(): Promise<string> {
  var numFoos = 0;

  workflow.setHandler(fooSignal, () => {
    numFoos++
  });

  workflow.setHandler(fooUpdate, () => {
    numFoos++
  });

  await workflow.condition(workflow.allHandlersFinished);
  return `foos: ${numFoos}`;
}

Starter:

  const handle = await client.workflow.start(workflowType, {
    workflowId,
    taskQueue: 'test',
    args,
  });
  await handle.signal('foo');
  await handle.startUpdate('foo', {
    waitForStage: WorkflowUpdateStage.ACCEPTED,
  });

Fixing this would require to break history compatibility or find a safe way to patch outside of the sandbox, which we haven't done before.

@dandavison
Copy link
Contributor Author

I'm concerned with allHandlersFinished returning true between handling of a signal and an update.

@bergundy and I discussed this. There is indeed a bug, though not introduced in this PR and therefore not blocking this PR. We've opened #1474

@dandavison dandavison force-pushed the 1434-warn-on-unfinished-handlers branch from f7cddea to 20337f9 Compare July 25, 2024 18:51
@Sushisource
Copy link
Member

Should also close #1435

@dandavison dandavison force-pushed the 1434-warn-on-unfinished-handlers branch from 2e61590 to 3f4dbce Compare August 2, 2024 04:04
@dandavison dandavison force-pushed the 1434-warn-on-unfinished-handlers branch from 4b1f1db to db05355 Compare August 2, 2024 18:19
@dandavison dandavison force-pushed the 1434-warn-on-unfinished-handlers branch from 3b7eb2a to f3ce8a1 Compare August 6, 2024 03:01
@dandavison dandavison force-pushed the 1434-warn-on-unfinished-handlers branch from f3ce8a1 to 5d4caca Compare August 6, 2024 03:20
@dandavison dandavison force-pushed the 1434-warn-on-unfinished-handlers branch from a363551 to 53a9ba5 Compare August 6, 2024 13:44
I initially thought we should keep it to make the documentation
maximally approachable, but I'm going back on that now.
Copy link
Contributor

@mjameswh mjameswh left a comment

Choose a reason for hiding this comment

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

Still a few nits, but I'm ok to fix those in a follow-up PR.

@dandavison dandavison force-pushed the 1434-warn-on-unfinished-handlers branch from 77240fe to 6fdbd32 Compare August 7, 2024 10:55
@dandavison dandavison merged commit dbbd597 into temporalio:main Aug 7, 2024
70 checks passed
@dandavison
Copy link
Contributor Author

Thanks very much for reviewing @mjameswh!

Still a few nits, but I'm ok to fix those in a follow-up PR.

The only thing I've pushed to a follow-up is the task of generating example stack traces to review our use of untrackPromise: #1486, which was needed even before this PR.

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.

Warn or error when update handlers dangle across CAN or workflow exit
4 participants