Skip to content
Permalink
Browse files

[JENKINS-46934] Avoid blocking forever due to log rotation.

· Call logRotate asynchronously.
· Impose a timeout on Owner.get.
· While waiting for Owner.get, record the build in the thread name.
  • Loading branch information...
jglick committed Sep 18, 2017
1 parent 3cb7c95 commit 63fdbe8c2d0f74f97e8f3b92cc566e2fff52bdf3
Showing with 16 additions and 4 deletions.
  1. +16 −4 src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java
@@ -676,10 +676,16 @@ private void finish(@Nonnull Result r, @CheckForNull Throwable t) {
duration = Math.max(0, System.currentTimeMillis() - getStartTimeInMillis());
try {
save();
getParent().logRotate();
} catch (Exception x) {
LOGGER.log(Level.WARNING, "failed to save " + this + " or perform log rotation", x);
LOGGER.log(Level.WARNING, "failed to save " + this, x);
}
Timer.get().submit(() -> {
try {
getParent().logRotate();
} catch (Exception x) {
LOGGER.log(Level.WARNING, "failed to perform log rotation after " + this, x);
}
});
onEndBuilding();
if (completed != null) {
synchronized (completed) {
@@ -894,12 +900,18 @@ private String key() {
@Override public FlowExecution get() throws IOException {
WorkflowRun r = run();
synchronized (LOADING_RUNS) {
while (r.execution == null && LOADING_RUNS.containsKey(key())) {
int count = 5;
while (r.execution == null && LOADING_RUNS.containsKey(key()) && count-- > 0) {
Thread thread = Thread.currentThread();
String origName = thread.getName();
thread.setName(origName + ": waiting for " + key());
try {
LOADING_RUNS.wait();
LOADING_RUNS.wait(/* 1m */60_000);
} catch (InterruptedException x) {
LOGGER.log(Level.WARNING, "failed to wait for " + r + " to be loaded", x);
break;
} finally {
thread.setName(origName);
}
}
}

0 comments on commit 63fdbe8

Please sign in to comment.
You can’t perform that action at this time.