Skip to content

Commit 1b53132

Browse files
authored
fix: prevent race conditions for concurrent npm-based server processes using same node_modules dir (diffplug#2786)
2 parents 5edf116 + 7b9e99b commit 1b53132

File tree

7 files changed

+12
-5
lines changed

7 files changed

+12
-5
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1212
## [Unreleased]
1313
### Added
1414
- Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757))
15+
### Fixed
16+
- 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))
1517
### Changes
1618
* Bump default `ktfmt` version to latest `0.59` -> `0.61`. ([2804](https://github.com/diffplug/spotless/pull/2804))
1719
* Bump default `ktlint` version to latest `1.7.1` -> `1.8.0`. ([2763](https://github.com/diffplug/spotless/pull/2763))

lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ function getInstanceId() {
3535

3636
var listener = app.listen(0, "127.0.0.1", () => {
3737
const instanceId = getInstanceId();
38+
const tempFileName = `server-${instanceId}.port.tmp`;
39+
const finalFileName = `server-${instanceId}.port`;
3840
debugLog("Server running on port " + listener.address().port + " for instance " + instanceId);
39-
fs.writeFile("server.port.tmp", "" + listener.address().port, function (err) {
41+
fs.writeFile(tempFileName, "" + listener.address().port, function (err) {
4042
if (err) {
4143
return console.log(err);
4244
} else {
43-
fs.rename("server.port.tmp", `server-${instanceId}.port`, function (err) {
45+
fs.rename(tempFileName, finalFileName, function (err) {
4446
if (err) {
4547
return console.log(err);
4648
}

lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spotless-eslint",
3-
"version": "4.0.0",
3+
"version": "4.0.1",
44
"description": "Spotless formatter step for running eslint as a rest service.",
55
"repository": "https://github.com/diffplug/spotless",
66
"license": "Apache-2.0",

lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spotless-prettier",
3-
"version": "4.0.0",
3+
"version": "4.0.1",
44
"description": "Spotless formatter step for running prettier as a rest service.",
55
"repository": "https://github.com/diffplug/spotless",
66
"license": "Apache-2.0",

lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spotless-tsfmt",
3-
"version": "4.0.0",
3+
"version": "4.0.1",
44
"description": "Spotless formatter step for running tsfmt as a rest service.",
55
"repository": "https://github.com/diffplug/spotless",
66
"license": "Apache-2.0",

plugin-gradle/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
77
- Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757))
88
### Fixed
99
- [fix] `NPE` due to workingTreeIterator being null for git ignored files. #911 ([#2771](https://github.com/diffplug/spotless/issues/2771))
10+
- 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))
1011
### Changes
1112
* Bump default `ktfmt` version to latest `0.59` -> `0.61`. ([2804](https://github.com/diffplug/spotless/pull/2804))
1213
* Bump default `ktlint` version to latest `1.7.1` -> `1.8.0`. ([2763](https://github.com/diffplug/spotless/pull/2763))

plugin-maven/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
77
- Add the ability to specify a wildcard version (`*`) for external formatter executables. ([#2757](https://github.com/diffplug/spotless/issues/2757))
88
### Fixed
99
- [fix] `NPE` due to workingTreeIterator being null for git ignored files. #911 ([#2771](https://github.com/diffplug/spotless/issues/2771))
10+
- 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))
11+
1012
### Changes
1113
* Bump default `ktfmt` version to latest `0.59` -> `0.61`. ([2804](https://github.com/diffplug/spotless/pull/2804))
1214
* Bump default `ktlint` version to latest `1.7.1` -> `1.8.0`. ([2763](https://github.com/diffplug/spotless/pull/2763))

0 commit comments

Comments
 (0)