Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #70 from jglick/logRotate-hang-JENKINS-46934
[JENKINS-46934] Avoid blocking forever due to log rotation
  • Loading branch information
abayer committed Sep 19, 2017
2 parents 3cb7c95 + 63fdbe8 commit c750cfe
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit c750cfe

Please sign in to comment.