Skip to content

Commit 769e3db

Browse files
authored
fix: normalize and replace line separator in node task lock file (#19092)
Normalizes and replaces line separators potentially present in the process command line before writing the lock file, so that it will contain only two lines. Same normalization is applied when getting the command line for the process identified by the pid in the lock file before comparing it with the value stored in the lock file. Fixes #19091
1 parent 73ddf02 commit 769e3db

File tree

1 file changed

+7
-2
lines changed
  • flow-server/src/main/java/com/vaadin/flow/server/frontend

1 file changed

+7
-2
lines changed

flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeTasks.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ private void getLock() {
363363
.of(lockInfo.pid());
364364

365365
if (processHandle.isPresent()
366-
&& processHandle.get().info().commandLine().orElse("")
366+
&& normalizeCommandLine(processHandle.get().info())
367367
.equals(lockInfo.commandLine())) {
368368
if (!loggedWaiting) {
369369
getLogger().info("Waiting for a previous instance of "
@@ -442,11 +442,16 @@ private NodeTasksLockInfo readLockFile()
442442
private void writeLockFile() throws IOException {
443443
ProcessHandle currentProcess = ProcessHandle.current();
444444
long myPid = currentProcess.pid();
445-
String commandLine = currentProcess.info().commandLine().orElse("");
445+
String commandLine = normalizeCommandLine(currentProcess.info());
446446
List<String> lines = List.of(Long.toString(myPid), commandLine);
447447
Files.write(lockFile, lines, StandardCharsets.UTF_8);
448448
}
449449

450+
private String normalizeCommandLine(ProcessHandle.Info processInfo) {
451+
return processInfo.commandLine()
452+
.map(line -> line.replaceAll("\\r?\\n", " \\\\n")).orElse("");
453+
}
454+
450455
private Logger getLogger() {
451456
return LoggerFactory.getLogger(getClass());
452457
}

0 commit comments

Comments
 (0)