Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-40368] Resources not locked after hard kill
  • Loading branch information
amuniz committed Feb 20, 2017
1 parent 3a8fb0e commit 3218afc
Showing 1 changed file with 15 additions and 7 deletions.
Expand Up @@ -255,7 +255,7 @@ public synchronized boolean lock(List<LockableResource> resources,
return !needToWait;
}

private synchronized void freeResources(List<String> unlockResourceNames, Run<?, ?> build) {
private synchronized void freeResources(List<String> unlockResourceNames, @Nullable Run<?, ?> build) {
for (String unlockResourceName : unlockResourceNames) {
for (LockableResource resource : this.resources) {
if (resource.getName().equals(unlockResourceName)) {
Expand All @@ -269,12 +269,12 @@ private synchronized void freeResources(List<String> unlockResourceNames, Run<?,
}
}

public synchronized void unlock(List<LockableResource> resourcesToUnLock, Run<?, ?> build) {
public synchronized void unlock(List<LockableResource> resourcesToUnLock, @Nullable Run<?, ?> build) {
unlock(resourcesToUnLock, build, false);
}

public synchronized void unlock(@Nullable List<LockableResource> resourcesToUnLock,
Run<?, ?> build, boolean inversePrecedence) {
@Nullable Run<?, ?> build, boolean inversePrecedence) {
List<String> resourceNamesToUnLock = new ArrayList<String>();
if (resourcesToUnLock != null) {
for (LockableResource r : resourcesToUnLock) {
Expand All @@ -285,7 +285,7 @@ public synchronized void unlock(@Nullable List<LockableResource> resourcesToUnLo
this.unlockNames(resourceNamesToUnLock, build, inversePrecedence);
}

public synchronized void unlockNames(@Nullable List<String> resourceNamesToUnLock, Run<?, ?> build, boolean inversePrecedence) {
public synchronized void unlockNames(@Nullable List<String> resourceNamesToUnLock, @Nullable Run<?, ?> build, boolean inversePrecedence) {
// make sure there is a list of resource names to unlock
if (resourceNamesToUnLock == null || (resourceNamesToUnLock.size() == 0)) {
return;
Expand Down Expand Up @@ -320,7 +320,7 @@ public synchronized void unlockNames(@Nullable List<String> resourceNamesToUnLoc
}

if (needToWait) {
this.freeResources(resourceNamesToUnLock, build);
freeResources(resourceNamesToUnLock, build);
save();
return;
} else {
Expand All @@ -332,7 +332,13 @@ public synchronized void unlockNames(@Nullable List<String> resourceNamesToUnLoc
requiredResource.setBuild(nextContext.getContext().get(Run.class));
resourceNamesToLock.add(requiredResource.getName());
} catch (Exception e) {
throw new IllegalStateException("Can not access the context of a running build", e);
// skip this context, as the build cannot be retrieved (maybe it was deleted while running?)
LOGGER.log(Level.WARNING, "Skipping queued context for lock. Can not get the Run object from the context to proceed with lock, " +
"this could be a legitimate status if the build waiting for the lock was deleted or" +
" hard killed. More information at Level.FINE if debug is needed.");
LOGGER.log(Level.FINE, "Can not get the Run object from the context to proceed with lock", e);
unlockNames(resourceNamesToUnLock, build, inversePrecedence);
return;
}
}

Expand All @@ -353,7 +359,7 @@ public synchronized void unlockNames(@Nullable List<String> resourceNamesToUnLoc
}

// free old resources no longer needed
this.freeResources(freeResources, build);
freeResources(freeResources, build);

// continue with next context
LockStepExecution.proceed(resourceNamesToLock, nextContext.getContext(), nextContext.getResourceDescription(), inversePrecedence);
Expand Down Expand Up @@ -575,4 +581,6 @@ public static LockableResourcesManager get() {
.getDescriptorOrDie(LockableResourcesManager.class);
}

private static final Logger LOGGER = Logger.getLogger(LockableResourcesManager.class.getName());

}

0 comments on commit 3218afc

Please sign in to comment.