-
Notifications
You must be signed in to change notification settings - Fork 959
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
Fixes if:cancelled()
composite steps not running and normal composite steps not interrupting when the job is cancelled.
#2638
Fixes if:cancelled()
composite steps not running and normal composite steps not interrupting when the job is cancelled.
#2638
Conversation
@@ -406,7 +415,7 @@ public void RegisterPostJobStep(IStep step) | |||
|
|||
/// <summary> | |||
/// An embedded execution context shares the same record ID, record name, logger, | |||
/// and a linked cancellation token. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -593,7 +602,31 @@ public void SetTimeout(TimeSpan? timeout) | |||
if (timeout != null) | |||
{ | |||
_cancellationTokenSource.CancelAfter(timeout.Value); | |||
m_timeoutSetAt = DateTime.UtcNow; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_timeoutSetAt
- perhaps m_timeoutStartedAt
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just m_startedAt
? so that elapsed = DateTime.UtcNow - m_startedAt.Value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather keep it m_timeoutStartedAt
to clearly imply it's for timeout related stuff, unlike _record.StartedAt
@@ -420,6 +422,8 @@ private async Task RunStepAsync(IStep step) | |||
{ | |||
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inherit the parent's remaining timeout
8f70490
to
c35f112
Compare
Also make composite step inherit timeout from parent
c35f112
to
e930403
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
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.
…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 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_status
was not set tocancelled
when the job is cancelled, which would allow anif: success()
composite step to not be interrupted in the event of cancellation. Fixed it by settingaction_status
tocancelled
inCompositeActionHandler
when 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()
cancelled
Workflow steps have their own cancellation tokens. When a job is cancelled, the currently running step's cancellation token is triggered, unless the step is
always
orcancelled
. 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
stepTimeout
set 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 isalways
orcancelled
. 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 arecancelled
oralways
.This bug does not show if the interrupted composite step is
always
orcancelled
, because then the shared token is not cancelled.Bug repro
fhammerl/nested-composite/actions/composite-steps@main