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

Avoid retrying if the build is aborted #134

Closed
wants to merge 1 commit into from
Closed

Avoid retrying if the build is aborted #134

wants to merge 1 commit into from

Conversation

felipecrs
Copy link

Refs #110 (comment)
Refs #110 (comment)

Testing done

This change was not tested yet, and I could not figure out how to make an automated test for it.

I'll let you know once I have tested it.

Submitter checklist

Preview Give feedback

Comment on lines 139 to 140
} catch (InterruptedIOException e) {
throw e;
Copy link
Author

Choose a reason for hiding this comment

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

I'm curious on what's the purpose of this. Perhaps it can be removed now.

/cc @dwnusbaum

Copy link
Author

@felipecrs felipecrs Mar 27, 2024

Choose a reason for hiding this comment

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

There are no more references in the code about it:

image

Perhaps it was meant to do what this PR actually does, and therefore could be removed.

Copy link
Author

Choose a reason for hiding this comment

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

Out of curiosity, the checkout to get Jenkinsfile step does the same thing:

https://github.com/jenkinsci/workflow-cps-plugin/pull/147/files#diff-751ef0b8272fefc4b69f6302b381e99ddc17417176a159adaf9e98e5d83566d4R144

And it is probably affected by the same problem.

Copy link
Author

Choose a reason for hiding this comment

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

And it is probably affected by the same problem.

I just confirmed here, it is. I'll craft a similar fix there.

Copy link
Member

@dwnusbaum dwnusbaum Mar 27, 2024

Choose a reason for hiding this comment

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

You would have to look through all implementations of SCM in other plugins and see if their checkout methods ever throw InterruptedIOException (keeping in mind that they might not throw it directly, but might use IO-related JDK APIs that in turn throw InterruptedIOException) to really know if it is unused or not.

Really, looking at jenkinsci/workflow-cps-plugin#147, I think the better fix would be to change the catch (Exception e) block here to catch (IOException e), so that instances of InterruptedException (which includes FlowInterruptedException) always bypass the retry logic, and then add a catch block for AbortException. In other words, use the exact same try/catch logic as in jenkinsci/workflow-cps-plugin#147.

Copy link
Member

@dwnusbaum dwnusbaum Mar 27, 2024

Choose a reason for hiding this comment

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

Oh, but then yes jenkinsci/workflow-cps-plugin#274 made workflow-cps have the same bad behavior. And then compare the third implementation over in https://github.com/jenkinsci/pipeline-groovy-lib-plugin/blob/83f864f66d8f827c442913c4e3f7000c3a52b5fb/src/main/java/org/jenkinsci/plugins/workflow/libs/SCMBasedRetriever.java#L218. Probably we need to create a helper method in workflow-api for this retry logic that handles all of the cases correctly.

Copy link
Author

Choose a reason for hiding this comment

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

use the exact same try/catch logic as in jenkinsci/workflow-cps-plugin#147.

But I just confirmed that one doesn't work either. It's affected by the same issue.

Copy link
Member

@dwnusbaum dwnusbaum Mar 27, 2024

Choose a reason for hiding this comment

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

IMO the logic seems like it should be like this: instances of InterruptedIOException and InterruptedException should bypass retries, except we need to check FlowInterruptedException, which is a subclass of InterruptedException, specially, and only skip retries if isActualInterruption().

Then, for any other Exception, we would retry, handling instances of AbortException specially as needed to avoid printing stack traces for them.

Copy link
Author

Choose a reason for hiding this comment

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

Probably we need to create a helper method in workflow-api for this retry logic that handles all of the cases correctly.

I totally agree with that. But this is kind of already done by the RetryStep:

https://github.com/jenkinsci/workflow-basic-steps-plugin/blob/686f0d7c0d9e235e958485a229552cc2da715626/src/main/java/org/jenkinsci/plugins/workflow/steps/RetryStepExecution.java

RetryStep works fine. It doesn't present this issue.

It would be nice if it could be reused here, but I am super inexperienced working with Jenkins plugins. I would appreciate if someone else can implement it, but please let me know if there is no intention in doing so.

@felipecrs
Copy link
Author

felipecrs commented Mar 27, 2024

Ok, this worked, no retries were executed and the build ended up aborted:

image

However, I don't get why it still prints "Checkout failed" and "Retrying after 10 seconds", as I re-throw the exception before reaching these lines.

@felipecrs
Copy link
Author

I'm not confident on merging this. I'd rather let some maintainer handle it.

@felipecrs felipecrs closed this Apr 10, 2024
@felipecrs felipecrs deleted the fix-abort branch April 10, 2024 17:31
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