adityaanikam opened a new pull request, #2841:
URL: https://github.com/apache/karaf/pull/2841

   Fixes #2808
   
   ## Problem
   
   `SimpleDownloadTask.download()` stages `wrap:`/`blueprint:`/`spring:` bundle 
URLs into a file named by hashing the URL, then does:
   
   ```java
   if (file.exists() && !file.delete()) { throw ...; }
   tmpFile.renameTo(file);
   ```
   
   Two overlapping resolutions of the same URL (e.g. two feature installs, each 
with their own `DownloadManager` -- dedup only happens within one instance) can 
race: the second one's `delete()` removes the first one's just-written file 
right as a third reader opens it, producing an intermittent 
`FileNotFoundException`. This is generic to the staging code, not any one jar, 
and shows up as needing multiple restarts before a container boots cleanly.
   
   ## Fix
   
   Replace the delete-then-rename with a single `Files.move(..., ATOMIC_MOVE)`, 
falling back to a plain move if the filesystem doesn't support atomic moves. A 
concurrent reader then always sees either the old or the new file, never a 
momentarily missing one.
   
   ## Testing
   
   Added `SimpleDownloadTaskTest`, which runs 200 rounds of 6 concurrent 
downloads racing on the same destination while a reader thread polls for the 
file transiently disappearing after having already existed once. Verified with 
a negative control: reverting only the fix (keeping the test) reproduces the 
race decisively -- 221,147 missing-file observations across the 200 rounds; 
restoring the fix brings that to zero.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to