Skip to content

Commit

Permalink
docker run: prevent concurrent unpacking of nar files
Browse files Browse the repository at this point in the history
  • Loading branch information
eolivelli committed Jan 26, 2024
1 parent f887bd6 commit a162471
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ public synchronized void scan() throws Exception {

public void handleNarFile(Path narFile) throws Exception {
String filename = narFile.getFileName().toString();
if (packages.containsKey(filename)) {
log.error(
"NarFileHandler ID: {} The package {} has already been processed",
System.identityHashCode(this),
filename);
log.error(
"NarFileHandler ID: {} Current packages: {}",
System.identityHashCode(this),
packages.keySet());
throw new IllegalStateException(
"The package " + filename + " has already been processed");
}

// first of all we look for an index file
try (ZipFile zipFile = new ZipFile(narFile.toFile())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,19 @@ public void run(
log.info("Code directory {}", codeDirectory);
log.info("Base persistent state directory {}", basePersistentStateDirectory);

boolean sharingNarFileHandler = sharedNarFileHandler != null;
List<URL> customLibClasspath = buildCustomLibClasspath(codeDirectory);
NarFileHandler narFileHandler =
sharedNarFileHandler != null
sharingNarFileHandler
? sharedNarFileHandler
: new NarFileHandler(
agentsDirectory,
customLibClasspath,
Thread.currentThread().getContextClassLoader());
try {
narFileHandler.scan();
if (!sharingNarFileHandler) {
narFileHandler.scan();
}

TopicConnectionsRuntimeRegistry topicConnectionsRuntimeRegistry =
new TopicConnectionsRuntimeRegistry();
Expand Down Expand Up @@ -208,7 +211,7 @@ public void run(
topicConnectionsRuntimeWithClassloader.close();
}
} finally {
if (sharedNarFileHandler == null) {
if (!sharingNarFileHandler) {
narFileHandler.close();
}
}
Expand Down

0 comments on commit a162471

Please sign in to comment.