fix: prevent race conditions for concurrent npm-based server processes using same node_modules dir#2786
Merged
nedtwigg merged 4 commits intodiffplug:mainfrom Jan 9, 2026
Conversation
…rs 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 diffplug#2462. Refs: diffplug#2462, diffplug#2542
node_modules dir
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a race condition that occurred when multiple npm-based formatters (prettier, eslint, tsfmt) launch their server processes simultaneously while sharing the same node_modules directory. The issue manifested as "ENOENT: no such file or directory, rename 'server.port.tmp'" errors because concurrent processes were colliding on the shared temporary filename.
Key Changes:
- Fixed race condition by including the instance ID in the temporary port filename
- Bumped npm package versions from 4.0.0 to 4.0.1 for all three formatters
- Updated changelog entries across all affected components
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lib/src/main/resources/com/diffplug/spotless/npm/common-serve.js | Core fix: changed server.port.tmp to use instance-specific filenames like server-{instanceId}.port.tmp to prevent concurrent access collisions |
| lib/src/main/resources/com/diffplug/spotless/npm/eslint-package.json | Version bump from 4.0.0 to 4.0.1 to reflect the bug fix |
| lib/src/main/resources/com/diffplug/spotless/npm/prettier-package.json | Version bump from 4.0.0 to 4.0.1 to reflect the bug fix |
| lib/src/main/resources/com/diffplug/spotless/npm/tsfmt-package.json | Version bump from 4.0.0 to 4.0.1 to reflect the bug fix |
| CHANGES.md | Added entry documenting the race condition fix |
| plugin-gradle/CHANGES.md | Added entry documenting the race condition fix for gradle plugin users |
| plugin-maven/CHANGES.md | Added entry documenting the race condition fix for maven plugin users |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
OK to merge for you @nedtwigg ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In #2462 and #2542 we added support for multiple npm-based formatters sharing the same
node_modulesdirectory.In my projects I noticed that - every once in a while - some of the npm-server-processes failed to start. This happened more often when configuration cache was active (and hence processes started faster). The lint files showed the following messages (example):
This PR fixes this race condition by making sure that the server-processes do not collide on the
server.port.tmpfile anymore, no matter the timing.