When you have yarnPath set to .yarn/releases/xxx and you run a script using yarn xxx, and then send a signal SIGTERM to the process, the signal is not necessarily propagated properly to the script and it may not exit as expected.
Using the repo I shared, in Linux, if I run the script using yarn runme it will spawn three processes. If I kill the first process, the other child processes are not killed. You may need to have yarn 4.x installed already in your path using corepack. If the yarn in your path is v1.x, it might not have the issue.
This took me quite some time to figure out and was very confusing.
When I tried removing .yarn/releases, the problem went away - it only runs using two processes, and the child termination is handled correctly if I kill the first process.
The reason this is a problem is that in production we are running in kubernetes and docker, and kubernetes kills the top process only. Because our script doesn't receive the signal, we are unable to gracefully shut down.
Note that although you can workaround this by not having .yarn/releases in place, I thought it would be helpful to at least document this problem here in case others run into it and are similarly stuck/confused by it. However, ideally this tricky issue wouldn't rear its head at all.
To reproduce
I was able to reproduce this on Linux and macOS using this repo and by running yarn && yarn runme.
Environment
System:
OS: Linux 6.5 Linux Mint 21.3 (Virginia)
CPU: (24) x64 AMD Ryzen 9 7900X3D 12-Core Processor
Binaries:
Node: 20.13.0 - /tmp/xfs-9b14e939/node
Yarn: 4.2.1 - /tmp/xfs-9b14e939/yarn
npm: 10.5.2 - ~/.nvm/versions/node/v20.13.0/bin/npm
Self-service
Describe the bug
When you have
yarnPath
set to.yarn/releases/xxx
and you run a script usingyarn xxx
, and then send a signalSIGTERM
to the process, the signal is not necessarily propagated properly to the script and it may not exit as expected.Prior issue: https://github.com/yarnpkg/berry/issues/5158 Reproduction: https://github.com/dobesv/yarn-exec-bug-repo
Using the repo I shared, in Linux, if I run the script using
yarn runme
it will spawn three processes. If I kill the first process, the other child processes are not killed. You may need to have yarn 4.x installed already in your path usingcorepack
. If the yarn in your path is v1.x, it might not have the issue.This took me quite some time to figure out and was very confusing.
When I tried removing
.yarn/releases
, the problem went away - it only runs using two processes, and the child termination is handled correctly if I kill the first process.The reason this is a problem is that in production we are running in kubernetes and docker, and kubernetes kills the top process only. Because our script doesn't receive the signal, we are unable to gracefully shut down.
Note that although you can workaround this by not having
.yarn/releases
in place, I thought it would be helpful to at least document this problem here in case others run into it and are similarly stuck/confused by it. However, ideally this tricky issue wouldn't rear its head at all.To reproduce
I was able to reproduce this on Linux and macOS using this repo and by running
yarn && yarn runme
.Environment
Additional context
No response