Skip to content

fix(workflow): Fix error when timer is cancelled and immediately fired in the same activation #466

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
merged 1 commit into from
Feb 3, 2022

Conversation

bergundy
Copy link
Member

@bergundy bergundy commented Feb 3, 2022

No description provided.

Comment on lines +1723 to +1731
makeActivation(
Date.now(),
{
signalWorkflow: { signalName: 'unblock', input: [] },
},
makeFireTimerJob(1)
)
);
compareCompletion(t, completion, makeSuccess([{ cancelTimer: { seq: 1 } }]));
Copy link
Member

Choose a reason for hiding this comment

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

How did you make this repro w/o the extra activation?

Copy link
Contributor

Choose a reason for hiding this comment

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

"extra"? I think w/ these two jobs:

        {
          signalWorkflow: { signalName: 'unblock', input: [] },
        },
        makeFireTimerJob(1)

It processes the first, which results in a cancel (and immediate cleanup/removal of timer completion), and then when it tries to process the second, it drops it because it can't find the completion (and assumes it must have been canceled). (or in the repro case, throws)

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue I had initially is that the fireTimer job doesn't get delivered if the workflow is already complete.
Adding another condition at the end of the workflow prevents that.


/** Consume a completion if it exists in Workflow state, throws if it doesn't */
export function consumeCompletion(type: keyof State['completions'], taskSeq: number): Completion {
const completion = maybeConsumeCompletion(type, taskSeq);
if (completion === undefined) {
throw new IllegalStateError(`No completion for taskSeq ${taskSeq}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should change that message too. "Completion" is a confusing word there. It's more like "No pending awaitable for...", no?

Now, are there any cases in which a user would see this error?

Copy link
Member Author

Choose a reason for hiding this comment

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

A user could see this error if new workflow code processes history generated by old code.

@bergundy bergundy merged commit 67526d3 into main Feb 3, 2022
@bergundy bergundy deleted the fix-timer-fired-right-after-cancelled branch February 3, 2022 22:15
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.

3 participants