Fixes if:cancelled() composite steps not running and normal composite steps not interrupting when the job is cancelled. - #2638
Merged
fhammerl merged 2 commits intoJul 10, 2023
Conversation
fhammerl
commented
Jun 30, 2023
|
|
||
| /// <summary> | ||
| /// An embedded execution context shares the same record ID, record name, logger, | ||
| /// and a linked cancellation token. |
Contributor
Author
There was a problem hiding this comment.
This token used to be linked so that stepTimeout would propagate down
We don't need to share a token if we set a new stepTimeout instead, calculated as parent step's timeout - timeElapsed
fhammerl
commented
Jun 30, 2023
| if (timeout != null) | ||
| { | ||
| _cancellationTokenSource.CancelAfter(timeout.Value); | ||
| m_timeoutSetAt = DateTime.UtcNow; |
Contributor
Author
There was a problem hiding this comment.
m_timeoutSetAt - perhaps m_timeoutStartedAt?
Member
There was a problem hiding this comment.
Just m_startedAt? so that elapsed = DateTime.UtcNow - m_startedAt.Value
Contributor
Author
There was a problem hiding this comment.
I'd rather keep it m_timeoutStartedAt to clearly imply it's for timeout related stuff, unlike _record.StartedAt
fhammerl
commented
Jun 30, 2023
| Trace.Info($"Starting: {step.DisplayName}"); | ||
| step.ExecutionContext.Debug($"Starting: {step.DisplayName}"); | ||
| // composite steps inherit the timeout from the parent, set by https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepstimeout-minutes | ||
| step.ExecutionContext.SetTimeout(step.ExecutionContext.Parent.GetRemainingTimeout()); |
Contributor
Author
There was a problem hiding this comment.
Inherit the parent's remaining timeout
fhammerl
force-pushed
the
fhammerl/fix-composite-cancelled-steps-not-running
branch
from
July 7, 2023 14:31
8f70490 to
c35f112
Compare
Also make composite step inherit timeout from parent
fhammerl
force-pushed
the
fhammerl/fix-composite-cancelled-steps-not-running
branch
from
July 10, 2023 10:02
c35f112 to
e930403
Compare
if:cancelled() composite steps not running and normal composite steps not interrupting when the job is cancelled.if:cancelled() composite steps not running and normal composite steps not interrupting when the job is cancelled.
ashb
pushed a commit
to ashb/runner
that referenced
this pull request
Jul 11, 2023
…te steps not interrupting when the job is cancelled. (actions#2638) * Set composite step's action_status when job is cancelled Also make composite step inherit timeout from parent * Fix eof line
This was referenced Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fix gives composite steps their own cancellation tokens instead of sharing one from their parent step (usually the workflow step that
uses:the composite action).This separation of tokens exposed a bug where
action_statuswas not set tocancelledwhen the job is cancelled, which would allow anif: success()composite step to not be interrupted in the event of cancellation. Fixed it by settingaction_statustocancelledinCompositeActionHandlerwhen the job is cancelled.Bug description: an
if:cancelled()composite action step is not always executed when the job is cancelled while the composite action is running.Such a step should run given:
uses:' it starts executing)cancelled()cancelledWorkflow steps have their own cancellation tokens. When a job is cancelled, the currently running step's cancellation token is triggered, unless the step is
alwaysorcancelled. The token of a 'success' step is cancelled. This token is used to interrupt any process invoked by that step, e.g. 'sleep 600'.Other steps, with their 'untriggered' cancellation tokens in the workflow are then evaluated for their
if:conditions and run accordingly.Composite action steps all share their parent steps cancellation token (in order to inherit a
stepTimeoutset on their parent step - this was introduced when composite actions could not have conditional steps). Just like in workflow steps: When a job is cancelled, the currently running step's cancellation token is triggered, unless the step isalwaysorcancelled. The token of a 'success' step is cancelled. This token is used to interrupt any process invoked by that step, e.g. 'sleep 600'.Other steps, with their 'untriggered' cancellation tokens in the workflow are then evaluated for their
if:conditions and try to run accordingly, but because they share a cancellation token, this token interrupts any process started by them, leading to none of these processes finishing, even if they arecancelledoralways.This bug does not show if the interrupted composite step is
alwaysorcancelled, because then the shared token is not cancelled.Bug repro
fhammerl/nested-composite/actions/composite-steps@main