From 91d568a4c0377fbea337f285f007fed9745c50a9 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 9 Dec 2025 20:45:55 +0100 Subject: [PATCH 1/4] fix: prevent name collisions when launching multiple node-based servers on same node_modules Before this change: if two (or more) node-based servers have been started on the same node_modules dir, the could override each others temporary port files, resulting in some of the servers not correctly launching. With this change: each server process makes sure to write distinct temporary and final files for transporting selected port number to the launching java process. This is a fixup for #2462. Refs: #2462, #2542 --- .../resources/com/diffplug/spotless/npm/common-serve.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js b/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js index edce61465a..9345d8c4d3 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js +++ b/lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js @@ -35,12 +35,14 @@ function getInstanceId() { var listener = app.listen(0, "127.0.0.1", () => { const instanceId = getInstanceId(); + const tempFileName = `server-${instanceId}.port.tmp`; + const finalFileName = `server-${instanceId}.port`; debugLog("Server running on port " + listener.address().port + " for instance " + instanceId); - fs.writeFile("server.port.tmp", "" + listener.address().port, function (err) { + fs.writeFile(tempFileName, "" + listener.address().port, function (err) { if (err) { return console.log(err); } else { - fs.rename("server.port.tmp", `server-${instanceId}.port`, function (err) { + fs.rename(tempFileName, finalFileName, function (err) { if (err) { return console.log(err); } From 1c0870f4c333bc3836231e66e6a03088f5c7b47c Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 9 Dec 2025 20:48:22 +0100 Subject: [PATCH 2/4] chore: bump versions for serve-packages due to logic changes Refs: #2462, #2542 --- .../resources/com/diffplug/spotless/npm/eslint-package.json | 2 +- .../resources/com/diffplug/spotless/npm/prettier-package.json | 2 +- .../main/resources/com/diffplug/spotless/npm/tsfmt-package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json index c4bdba5209..c8e08d19b9 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json @@ -1,6 +1,6 @@ { "name": "spotless-eslint", - "version": "4.0.0", + "version": "4.0.1", "description": "Spotless formatter step for running eslint as a rest service.", "repository": "https://github.com/diffplug/spotless", "license": "Apache-2.0", diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json index a7c219625c..6ee6ed68a5 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json @@ -1,6 +1,6 @@ { "name": "spotless-prettier", - "version": "4.0.0", + "version": "4.0.1", "description": "Spotless formatter step for running prettier as a rest service.", "repository": "https://github.com/diffplug/spotless", "license": "Apache-2.0", diff --git a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json index d6c9a8a656..f84a257c64 100644 --- a/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json +++ b/lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json @@ -1,6 +1,6 @@ { "name": "spotless-tsfmt", - "version": "4.0.0", + "version": "4.0.1", "description": "Spotless formatter step for running tsfmt as a rest service.", "repository": "https://github.com/diffplug/spotless", "license": "Apache-2.0", From c70dee0f0b39c906228e05c79fd4b9e8b6e40736 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 9 Dec 2025 20:53:45 +0100 Subject: [PATCH 3/4] docs: add fix to changelog --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 1 + plugin-maven/CHANGES.md | 2 ++ 3 files changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index d3bb7eacf1..122c09416e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added - Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757)) +### Fixed +- Prevent race conditions when multiple npm-based formatters launch the server process simultaneously while sharing the same `node_modules` directory. ([#????](https://github.com/diffplug/spotless/pull/????)) ### Changes * Bump default `ktlint` version to latest `1.7.1` -> `1.8.0`. ([2763](https://github.com/diffplug/spotless/pull/2763)) * Bump default `gherkin-utils` version to latest `9.2.0` -> `10.0.0`. ([#2619](https://github.com/diffplug/spotless/pull/2619)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b9de11b3a1..aa96eb7932 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757)) ### Fixed - [fix] `NPE` due to workingTreeIterator being null for git ignored files. #911 ([#2771](https://github.com/diffplug/spotless/issues/2771)) +- Prevent race conditions when multiple npm-based formatters launch the server process simultaneously while sharing the same `node_modules` directory. ([#????](https://github.com/diffplug/spotless/pull/????)) ### Changes * Bump default `ktlint` version to latest `1.7.1` -> `1.8.0`. ([2763](https://github.com/diffplug/spotless/pull/2763)) * Bump default `gherkin-utils` version to latest `9.2.0` -> `10.0.0`. ([#2619](https://github.com/diffplug/spotless/pull/2619)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index d996ecc6d8..ec36720c22 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,6 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757)) ### Fixed - [fix] `NPE` due to workingTreeIterator being null for git ignored files. #911 ([#2771](https://github.com/diffplug/spotless/issues/2771)) +- Prevent race conditions when multiple npm-based formatters launch the server process simultaneously while sharing the same `node_modules` directory. ([#????](https://github.com/diffplug/spotless/pull/????)) + ### Changes * Bump default `ktlint` version to latest `1.7.1` -> `1.8.0`. ([2763](https://github.com/diffplug/spotless/pull/2763)) * Bump default `gherkin-utils` version to latest `9.2.0` -> `10.0.0`. ([#2619](https://github.com/diffplug/spotless/pull/2619)) From 7b9e99b53b2f9a195230d4212ebe5b06a8986090 Mon Sep 17 00:00:00 2001 From: Simon Gamma Date: Tue, 9 Dec 2025 21:02:49 +0100 Subject: [PATCH 4/4] docs: use assigned PR number --- CHANGES.md | 2 +- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 122c09416e..e83b6c4f78 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,7 +13,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added - Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757)) ### Fixed -- Prevent race conditions when multiple npm-based formatters launch the server process simultaneously while sharing the same `node_modules` directory. ([#????](https://github.com/diffplug/spotless/pull/????)) +- Prevent race conditions when multiple npm-based formatters launch the server process simultaneously while sharing the same `node_modules` directory. ([#2786](https://github.com/diffplug/spotless/pull/2786)) ### Changes * Bump default `ktlint` version to latest `1.7.1` -> `1.8.0`. ([2763](https://github.com/diffplug/spotless/pull/2763)) * Bump default `gherkin-utils` version to latest `9.2.0` -> `10.0.0`. ([#2619](https://github.com/diffplug/spotless/pull/2619)) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index aa96eb7932..f730ee2d8b 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -7,7 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757)) ### Fixed - [fix] `NPE` due to workingTreeIterator being null for git ignored files. #911 ([#2771](https://github.com/diffplug/spotless/issues/2771)) -- Prevent race conditions when multiple npm-based formatters launch the server process simultaneously while sharing the same `node_modules` directory. ([#????](https://github.com/diffplug/spotless/pull/????)) +- Prevent race conditions when multiple npm-based formatters launch the server process simultaneously while sharing the same `node_modules` directory. ([#2786](https://github.com/diffplug/spotless/pull/2786)) ### Changes * Bump default `ktlint` version to latest `1.7.1` -> `1.8.0`. ([2763](https://github.com/diffplug/spotless/pull/2763)) * Bump default `gherkin-utils` version to latest `9.2.0` -> `10.0.0`. ([#2619](https://github.com/diffplug/spotless/pull/2619)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index ec36720c22..48b61bc347 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,7 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757)) ### Fixed - [fix] `NPE` due to workingTreeIterator being null for git ignored files. #911 ([#2771](https://github.com/diffplug/spotless/issues/2771)) -- Prevent race conditions when multiple npm-based formatters launch the server process simultaneously while sharing the same `node_modules` directory. ([#????](https://github.com/diffplug/spotless/pull/????)) +- Prevent race conditions when multiple npm-based formatters launch the server process simultaneously while sharing the same `node_modules` directory. ([#2786](https://github.com/diffplug/spotless/pull/2786)) ### Changes * Bump default `ktlint` version to latest `1.7.1` -> `1.8.0`. ([2763](https://github.com/diffplug/spotless/pull/2763))