diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2022-05-27 16:20:28 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2022-05-27 16:20:28 +0200 |
commit | 9612aae885bd2247455163531e853576b4caebd6 (patch) | |
tree | 8870d405f13c217bcf9145bf68104b9a533a278e /org.eclipse.jgit/src/org | |
parent | cec6db62af51a43e4c121f135a98de443ef0cd2c (diff) | |
parent | d67ac798f10254d038c49244e7f1e2323afdfdfc (diff) | |
download | jgit-9612aae885bd2247455163531e853576b4caebd6.tar.gz jgit-9612aae885bd2247455163531e853576b4caebd6.zip |
Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
Remove stray files (probes or lock files) created by background threads
Change-Id: I7af1355a77f14995118145162f6bb8a4f1755f2b
Diffstat (limited to 'org.eclipse.jgit/src/org')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java | 5 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java | 31 |
2 files changed, 27 insertions, 9 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java index 7b5f00e4fe..2443c4e771 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java @@ -216,9 +216,10 @@ public class FileBasedConfig extends StoredConfig { } final LockFile lf = new LockFile(getFile()); - if (!lf.lock()) - throw new LockFailedException(getFile()); try { + if (!lf.lock()) { + throw new LockFailedException(getFile()); + } lf.setNeedSnapshotNoConfig(true); lf.write(out); if (!lf.commit()) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index 9237c0a9b2..e8f38d8fd9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -47,7 +47,6 @@ import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; @@ -262,8 +261,9 @@ public abstract class FS { * * @see java.util.concurrent.Executors#newCachedThreadPool() */ - private static final Executor FUTURE_RUNNER = new ThreadPoolExecutor(0, - 5, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), + private static final ExecutorService FUTURE_RUNNER = new ThreadPoolExecutor( + 0, 5, 30L, TimeUnit.SECONDS, + new LinkedBlockingQueue<Runnable>(), runnable -> { Thread t = new Thread(runnable, "JGit-FileStoreAttributeReader-" //$NON-NLS-1$ @@ -285,8 +285,9 @@ public abstract class FS { * small keep-alive time to avoid delays on shut-down. * </p> */ - private static final Executor SAVE_RUNNER = new ThreadPoolExecutor(0, 1, - 1L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), + private static final ExecutorService SAVE_RUNNER = new ThreadPoolExecutor( + 0, 1, 1L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<Runnable>(), runnable -> { Thread t = new Thread(runnable, "JGit-FileStoreAttributeWriter-" //$NON-NLS-1$ @@ -296,6 +297,18 @@ public abstract class FS { return t; }); + static { + // Shut down the SAVE_RUNNER on System.exit() + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + SAVE_RUNNER.shutdownNow(); + SAVE_RUNNER.awaitTermination(100, TimeUnit.MILLISECONDS); + } catch (Exception e) { + // Ignore; we're shutting down + } + })); + } + /** * Whether FileStore attributes should be determined asynchronously * @@ -452,11 +465,13 @@ public abstract class FS { return null; } // fall through and return fallback - } catch (IOException | InterruptedException - | ExecutionException | CancellationException e) { + } catch (IOException | ExecutionException | CancellationException e) { LOG.error(e.getMessage(), e); } catch (TimeoutException | SecurityException e) { // use fallback + } catch (InterruptedException e) { + LOG.error(e.getMessage(), e); + Thread.currentThread().interrupt(); } LOG.debug("{}: use fallback timestamp resolution for directory {}", //$NON-NLS-1$ Thread.currentThread(), dir); @@ -474,6 +489,7 @@ public abstract class FS { Path probe = dir.resolve(".probe-" + UUID.randomUUID()); //$NON-NLS-1$ Instant end = Instant.now().plusSeconds(3); try { + probe.toFile().deleteOnExit(); Files.createFile(probe); do { n++; @@ -540,6 +556,7 @@ public abstract class FS { } Path probe = dir.resolve(".probe-" + UUID.randomUUID()); //$NON-NLS-1$ try { + probe.toFile().deleteOnExit(); Files.createFile(probe); Duration fsResolution = getFsResolution(s, dir, probe); Duration clockResolution = measureClockResolution(); |