yarnpkg / yarnpkg/berry

[Bug?]: Does not propagate signals to child process when using yarnPath in a project

Open
#6,299 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
8.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Self-service
  • I'd be willing to implement a fix
Describe the bug

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.

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 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
Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository on Linux or macOS and compare the process tree and SIGTERM behavior with and without .yarn/releases. Trace the yarnPath execution path and its child-process signal handling. Done means a script launched through yarn runme receives SIGTERM and its child processes terminate as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.