Make Computer#getLogDir thread-safe (#4730)

This commit is contained in:
Vincent Latombe authored and GitHub committed 2020-05-23 13:16:05 +01:00
1 parent 6e11d6124b
commit 4c16f2cd95
1 file changed
+8 -4
@@ -195,6 +195,8 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
protected final Object statusChangeLock = new Object();
private final Object logDirLock = new String("logDirLock");
/**
* Keeps track of stack traces to track the termination requests for this computer.
*
@@ -303,10 +305,12 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
*/
protected @NonNull File getLogDir() {
File dir = new File(Jenkins.get().getRootDir(),"logs/slaves/"+nodeName);
try {
IOUtils.mkdirs(dir);
} catch (IOException x) {
LOGGER.log(Level.SEVERE, "Failed to create agent log directory " + dir, x);
synchronized (logDirLock) {
try {
IOUtils.mkdirs(dir);
} catch (IOException x) {
LOGGER.log(Level.SEVERE, "Failed to create agent log directory " + dir, x);
}
}
return dir;
}