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 (argo wait): use functions to constrain ctx instead of blocks #10140

Merged
merged 2 commits into from
Dec 1, 2022

Conversation

sxllwx
Copy link
Contributor

@sxllwx sxllwx commented Nov 30, 2022

Signed-off-by: scott scottwangsxll@gmail.com

Fixes: as the title says

Please do not open a pull request until you have checked ALL of these:

  • Create the PR as draft .
  • Run make pre-commit -B to fix codegen and lint problems.
  • Sign-off your commits (otherwise the DCO check will fail).
  • Use a conventional commit message (otherwise the commit message check will fail).
  • "Fixes #" is in both the PR title (for release notes) and this description (to automatically link and close the issue).
  • Add unit or e2e tests. Say how you tested your changes. If you changed the UI, attach screenshots.
  • Github checks are green.
  • Once required tests have passed, mark your PR "Ready for review".

If changes were requested, and you've made them, dismiss the review to get it reviewed again.

@sxllwx sxllwx marked this pull request as draft November 30, 2022 07:14
@sxllwx sxllwx marked this pull request as ready for review November 30, 2022 07:17
@alexec
Copy link
Contributor

alexec commented Nov 30, 2022

What problem does this fix?

Signed-off-by: scott <scottwangsxll@gmail.com>
@sxllwx
Copy link
Contributor Author

sxllwx commented Dec 1, 2022

Please correct me if I understand wrong, thx.

     // use a function to constrain the scope of ctx
      {
		// this allows us to gracefully shutdown, capturing artifacts
		ctx, cancel := signal.NotifyContext(ctx, syscall.SIGTERM)
		defer cancel()

		// Wait for main container to complete
		err := wfExecutor.Wait(ctx)
		if err != nil {
			wfExecutor.AddError(err)
		}
	}

As mentioned in the comment, the block here is to limit the scope of ctx. expected execution result is to call cancel after the scope of ctx ends (that is, when the code segment of the block is executed). However, due to the use of the defer keyword, defer will only be executed after the end of the function, not after the end of the code segment in the block.

sample-code: https://go.dev/play/p/Bvwy9tswNm8

ps: The current code runs without any problems. This patch will make our code more grammatically correct. 😄

Copy link
Contributor

@alexec alexec left a comment

Choose a reason for hiding this comment

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

Better grammar is good!

@alexec alexec enabled auto-merge (squash) December 1, 2022 14:41
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.

2 participants