Skip to content

Commit db22812

Browse files
committed
Prevent sending interrupt signals by lost killer tasks by activity
When many activity timeouts are run at the same time, sometimes the "Sending interrupt signal to process" message appears and the build is aborted (JENKINS-58752). The "Cancelling nested steps due to timeout" message is never printed. The code has been refactored to prevent such issues: - the implementation of the activity and absolute timeouts have been separated to improve the code readability - the tasks executed after a delay are always created in synchronized sections, to prevent losing tasks which should be canceled - the timer logic of the activity timeout is changed from always stopping to verifying if the logic should be stopped or continued, so the number of timers is always under control (less instances) - the `Tick` class is replaced by a listener which notifies the step less frequently about the changes. The behavior could be controlled by setting the `org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.activityNotifyWaitRatio` property. It informs when the earliest the information about new activities should be sent to the timeout (`time * ratio`). When there were no activities in that time, then the next activity will be announced right after it has been reported There are additional changes introduced in this commit: - the timeout id is always printed in the log messages which improves debugging (e.g. when timeouts are nested) - the logic is more precise. The previous implementation allowed exceeding the timeout by 1/10 of the time (JENKINS-63696). The new stops the process right after the timeout is reached. There is a property to allow exceeding it a little bit - `org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.activityPrecision`. It is necessary to not abort the logic due to delay in the notification process.
1 parent dfe1ba1 commit db22812

2 files changed

Lines changed: 458 additions & 0 deletions

File tree

src/main/java/org/jenkinsci/plugins/workflow/steps/TimeoutStep.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import hudson.Extension;
55
import hudson.model.TaskListener;
66
import hudson.util.ListBoxModel;
7+
import jenkins.util.SystemProperties;
78
import org.kohsuke.stapler.DataBoundConstructor;
89
import org.kohsuke.stapler.DataBoundSetter;
910

@@ -59,6 +60,9 @@ public DescriptorImpl getDescriptor() {
5960

6061
@Override
6162
public StepExecution start(StepContext context) throws Exception {
63+
if (SystemProperties.getBoolean(TimeoutStep.class.getName() + ".threadsafe")) {
64+
return new TimeoutStepExecutionThreadSafe(this, context);
65+
}
6266
return new TimeoutStepExecution(this, context);
6367
}
6468

0 commit comments

Comments
 (0)