Skip to content

Conversation

@simschla
Copy link
Contributor

@simschla simschla commented Dec 9, 2025

In #2462 and #2542 we added support for multiple npm-based formatters sharing the same node_modules directory.
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):

Process result:
> arguments: [/path/to/repo/.gradle/nodejs/node-v24.11.1-darwin-arm64/bin/npm, start, --scripts-prepend-node-path=true, --, --node-server-instance-id=d61a85af-5417-40d9-9fa7-369ded8b7921]
> exit code: 0
>    stdout: (below)
> npm warn Unknown cli config "--scripts-prepend-node-path". This will stop working in the next major version of npm.
> 
> > spotless-prettier@4.0.0 start
> > node serve.js --node-server-instance-id=***
> 
> [Error: ENOENT: no such file or directory, rename 'server.port.tmp' -> 'server-d61a85af-5417-40d9-9fa7-369ded8b7921.port'] {
>   errno: -2,
>   code: 'ENOENT',
>   syscall: 'rename',
>   path: 'server.port.tmp',
>   dest: 'server-d61a85af-5417-40d9-9fa7-369ded8b7921.port'
> }

This PR fixes this race condition by making sure that the server-processes do not collide on the server.port.tmp file anymore, no matter the timing.

…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
@simschla simschla requested a review from Copilot December 9, 2025 20:03
@simschla simschla changed the title fix: prevent name collisions for concurrent npm-based server processes fix: prevent race conditions for concurrent npm-based server processes using same node_modules dir Dec 9, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant