Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
[JENKINS-30395] Trying to diagnose the root cause of a recurrent Clos…
Browse files Browse the repository at this point in the history
…edByInterruptException in CI.
  • Loading branch information
jglick committed Dec 16, 2015
1 parent 521099b commit ed77fb9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Expand Up @@ -34,6 +34,7 @@
import hudson.slaves.SlaveComputer;
import java.io.File;
import java.io.IOException;
import java.security.Permission;
import java.util.Collections;
import java.util.Map;
import javax.annotation.CheckForNull;
Expand Down Expand Up @@ -80,6 +81,38 @@ private static class SpecialEnvComputer extends SlaveComputer {
}
}

/**
* Prints a stack trace whenever {@link Thread#interrupt} is called on a thread running {@link JenkinsRule#before}.
*/
public static void diagnoseJenkins30395() {
System.setSecurityManager(new SecurityManager() {
@Override public void checkAccess(Thread t) {
StackTraceElement[] target = t.getStackTrace();
if (matches(target, JenkinsRule.class, "before")) {
Throwable x = new Throwable("calling Thread.interrupt here");
if (matches(x.getStackTrace(), Thread.class, "interrupt")) {
x.printStackTrace();
System.err.println("Target thread:");
for (StackTraceElement line : target) {
System.err.println("\tat " + line);
}
}
}
}
boolean matches(StackTraceElement[] stack, Class<?> clazz, String method) {
String n = clazz.getName();
for (StackTraceElement line : stack) {
if (line.getClassName().equals(n) && line.getMethodName().equals(method)) {
return true;
}
}
return false;
}
@Override public void checkPermission(Permission perm) {}
@Override public void checkPermission(Permission perm, Object context) {}
});
}

private JenkinsRuleExt() {}

}
Expand Up @@ -32,6 +32,7 @@
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.jvnet.hudson.test.BuildWatcher;
Expand All @@ -45,6 +46,10 @@
*/
public abstract class SingleJobTestBase extends Assert {

@BeforeClass public static void diagnoseJenkins30395() {
JenkinsRuleExt.diagnoseJenkins30395();
}

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public RestartableJenkinsRule story = new RestartableJenkinsRule();

Expand Down
Expand Up @@ -42,6 +42,7 @@
import org.jenkinsci.plugins.workflow.support.actions.LogActionImpl;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
Expand All @@ -53,6 +54,10 @@
*/
public class WorkflowJobNonRestartingTest extends AbstractCpsFlowTest {

@BeforeClass public static void diagnoseJenkins30395() {
JenkinsRuleExt.diagnoseJenkins30395();
}

WorkflowJob p;

@Before public void setUp() throws Exception {
Expand Down
Expand Up @@ -55,6 +55,7 @@
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -65,6 +66,10 @@

public class WorkflowRunTest {

@BeforeClass public static void diagnoseJenkins30395() {
JenkinsRuleExt.diagnoseJenkins30395();
}

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public JenkinsRule r = new JenkinsRule();

Expand Down

0 comments on commit ed77fb9

Please sign in to comment.