yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.37k stars 2.72k forks source link

Network mutex may enter infinite recursion if port is in use by non-Yarn #9046

Open robhogan opened 2 months ago

robhogan commented 2 months ago

Yarn classic is unmaintained - I'm just noting this here as a point of reference/pointer for others

When using --mutex=network, Yarn attempts to start an HTTP server on the configured port. If it fails, it tries to ask whatever is listening for its name, and then waits for it if it appears to be a Yarn process.

This can go wrong in a few ways, often leading to infinite recursion due to the retry behaviour.

https://github.com/yarnpkg/yarn/blob/158d96dce95313d9a00218302631cd263877d164/src/cli/index.js#L419-L447

The only circumstance where Yarn correctly reports Cannot use the network mutex on port 31997. It is probably used by another app is when the listening process is an HTTP server that responds with anything other than JSON.

We're patching this locally by not retrying with startServer() on errors, and adding a timeout for unresponsive sockets.