Skip to content
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

fix(stepfunctions): prefixes not appended to states in parallel branches #17806

Merged
merged 5 commits into from
Dec 6, 2021
Merged

fix(stepfunctions): prefixes not appended to states in parallel branches #17806

merged 5 commits into from
Dec 6, 2021

Conversation

kaizencc
Copy link
Contributor

@kaizencc kaizencc commented Dec 1, 2021

There is an order mismatch issue when calling Parallel.branch(). branch used to immediately create the state graph of the branch which locks in the stateIds of the branch states. This fails to take into account the following scenario:

class ParallelMachineFragment extends stepfunctions.StateMachineFragment {
  public readonly startState: stepfunctions.State;
  public readonly endStates: stepfunctions.INextable[];

  constructor(scope: Construct, id: string) {
    super(scope, id);

    const step1 = new stepfunctions.Pass(this, 'Step 1');
    const parallelState = new stepfunctions.Parallel(this, 'Parallel State');
    const chain = parallelState.branch(step1);
    this.startState = parallelState;
    this.endStates = [chain];
  }
}

class MyStack extends Stack {
  constructor(scope: Construct, id: string) {
    const fragment1 = new ParallelMachineFragment(this, 'Fragment 1').prefixStates();
    const fragment2 = new ParallelMachineFragment(this, 'Fragment 2').prefixStates();
    
    new stepfunctions.StateMachine(stack, 'State Machine', {
      definition: fragment1.next(fragment2),
    });
  }
}

Here, the branches in the parallelState do not get prefixes before they are evaluated, causing an error since they have the same stateId.

The fix is to make the state graph creation late-bound; it now happens when we call Parallel.bindToGraph(). At this point, it will know of any prefixes.

Fixes #17354.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@kaizencc kaizencc requested a review from rix0rrr December 1, 2021 20:59
@kaizencc kaizencc self-assigned this Dec 1, 2021
@gitpod-io
Copy link

gitpod-io bot commented Dec 1, 2021

@github-actions github-actions bot added the @aws-cdk/aws-stepfunctions Related to AWS StepFunctions label Dec 1, 2021
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Dec 1, 2021
@kaizencc kaizencc requested a review from rix0rrr December 3, 2021 23:13
@mergify
Copy link
Contributor

mergify bot commented Dec 6, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 09669dc
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit a1da772 into aws:master Dec 6, 2021
@mergify
Copy link
Contributor

mergify bot commented Dec 6, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@kaizencc kaizencc deleted the sfn-bug branch December 8, 2021 20:35
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…hes (aws#17806)

There is an order mismatch issue when calling `Parallel.branch()`. `branch` used to immediately create the state graph of the branch which locks in the `stateIds` of the branch states. This fails to take into account the following scenario: 

```ts
class ParallelMachineFragment extends stepfunctions.StateMachineFragment {
  public readonly startState: stepfunctions.State;
  public readonly endStates: stepfunctions.INextable[];

  constructor(scope: Construct, id: string) {
    super(scope, id);

    const step1 = new stepfunctions.Pass(this, 'Step 1');
    const parallelState = new stepfunctions.Parallel(this, 'Parallel State');
    const chain = parallelState.branch(step1);
    this.startState = parallelState;
    this.endStates = [chain];
  }
}

class MyStack extends Stack {
  constructor(scope: Construct, id: string) {
    const fragment1 = new ParallelMachineFragment(this, 'Fragment 1').prefixStates();
    const fragment2 = new ParallelMachineFragment(this, 'Fragment 2').prefixStates();
    
    new stepfunctions.StateMachine(stack, 'State Machine', {
      definition: fragment1.next(fragment2),
    });
  }
}
```

Here, the branches in the `parallelState` do not get prefixes before they are evaluated, causing an error since they have the same `stateId`.

The fix is to make the state graph creation late-bound; it now happens when we call `Parallel.bindToGraph()`. At this point, it will know of any prefixes. 

Fixes aws#17354. 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-stepfunctions Related to AWS StepFunctions contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws_stepfunctions): Parallel inside StateMachineFragment causes validation errors
4 participants