Skip to content

Commit

Permalink
[JENKINS-50504] WorkspaceList.inUse should be keyed by String not Fil…
Browse files Browse the repository at this point in the history
…ePath so leases survive agent reconnections.
  • Loading branch information
jglick committed Apr 1, 2019
1 parent 811583e commit 15a0c39
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions core/src/main/java/hudson/slaves/WorkspaceList.java
Expand Up @@ -155,7 +155,7 @@ public void release() {
}
}

private final Map<FilePath,Entry> inUse = new HashMap<>();
private final Map<String, Entry> inUse = new HashMap<>();

public WorkspaceList() {
}
Expand All @@ -181,7 +181,7 @@ public synchronized Lease allocate(@Nonnull FilePath base) throws InterruptedExc
public synchronized Lease allocate(@Nonnull FilePath base, Object context) throws InterruptedException {
for (int i=1; ; i++) {
FilePath candidate = i==1 ? base : base.withSuffix(COMBINATOR+i);
Entry e = inUse.get(candidate);
Entry e = inUse.get(candidate.getRemote());
if(e!=null && !e.quick && e.context!=context)
continue;
return acquire(candidate,false,context);
Expand All @@ -195,7 +195,7 @@ public synchronized Lease record(@Nonnull FilePath p) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "recorded " + p, new Throwable("from " + this));
}
Entry old = inUse.put(p, new Entry(p, false));
Entry old = inUse.put(p.getRemote(), new Entry(p, false));
if (old!=null)
throw new AssertionError("Tried to record a workspace already owned: "+old);
return lease(p);
Expand All @@ -205,15 +205,15 @@ public synchronized Lease record(@Nonnull FilePath p) {
* Releases an allocated or acquired workspace.
*/
private synchronized void _release(@Nonnull FilePath p) {
Entry old = inUse.get(p);
Entry old = inUse.get(p.getRemote());
if (old==null)
throw new AssertionError("Releasing unallocated workspace "+p);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "releasing " + p + " with lock count " + old.lockCount, new Throwable("from " + this));
}
old.lockCount--;
if (old.lockCount==0)
inUse.remove(p);
inUse.remove(p.getRemote());
notifyAll();
}

Expand Down Expand Up @@ -253,7 +253,7 @@ public synchronized Lease acquire(@Nonnull FilePath p, boolean quick, Object con
t.setName("Waiting to acquire "+p+" : "+t.getName());
try {
while (true) {
e = inUse.get(p);
e = inUse.get(p.getRemote());
if (e==null || e.context==context)
break;
wait();
Expand All @@ -266,7 +266,7 @@ public synchronized Lease acquire(@Nonnull FilePath p, boolean quick, Object con
}

if (e!=null) e.lockCount++;
else inUse.put(p,new Entry(p,quick,context));
else inUse.put(p.getRemote(), new Entry(p,quick,context));
return lease(p);
}

Expand Down

0 comments on commit 15a0c39

Please sign in to comment.