From 15a0c3947469e3d9aadf9f3c15c1a4db1ea088af Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 1 Apr 2019 15:30:09 -0400 Subject: [PATCH] [JENKINS-50504] WorkspaceList.inUse should be keyed by String not FilePath so leases survive agent reconnections. --- .../src/main/java/hudson/slaves/WorkspaceList.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/hudson/slaves/WorkspaceList.java b/core/src/main/java/hudson/slaves/WorkspaceList.java index 97283fd6d7ae..bf52303139f2 100644 --- a/core/src/main/java/hudson/slaves/WorkspaceList.java +++ b/core/src/main/java/hudson/slaves/WorkspaceList.java @@ -155,7 +155,7 @@ public void release() { } } - private final Map inUse = new HashMap<>(); + private final Map inUse = new HashMap<>(); public WorkspaceList() { } @@ -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); @@ -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); @@ -205,7 +205,7 @@ 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)) { @@ -213,7 +213,7 @@ private synchronized void _release(@Nonnull FilePath p) { } old.lockCount--; if (old.lockCount==0) - inUse.remove(p); + inUse.remove(p.getRemote()); notifyAll(); } @@ -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(); @@ -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); }