Skip to content

Commit

Permalink
Harden JarCacheSupport (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Jan 8, 2024
1 parent b6a2c27 commit 399fb9b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/java/hudson/remoting/JarCacheSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ public DownloadRunnable(Channel channel, long sum1, long sum2, Checksum key, Com
public void run() {
try {
URL url = retrieve(channel, sum1, sum2);
inprogress.remove(key);
promise.complete(url);
if (inprogress.remove(key, promise)) {
promise.complete(url);
} else {
promise.completeExceptionally(new IllegalStateException("Download is (unexpectedly) no longer in progress"));
}
} catch (ChannelClosedException | RequestAbortedException e) {
// the connection was killed while we were still resolving the file
bailout(e);
Expand All @@ -112,7 +115,7 @@ public void run() {
* Report a failure of the retrieval and allows another thread to retry.
*/
private void bailout(Throwable e) {
inprogress.remove(key); // this lets another thread to retry later
inprogress.remove(key, promise); // this lets another thread to retry later
promise.completeExceptionally(e); // then tell those who are waiting that we aborted
}
}
Expand Down

0 comments on commit 399fb9b

Please sign in to comment.