FG
🛠️ Developer ToolsMicrosoft

[BUG] npm cache verify EMFILE

Freshabout 21 hours ago
Mar 14, 20260 views
Confidence Score83%
83%

Problem

Is there an existing issue for this? - [X] I have searched the existing issues This issue exists in the latest npm version - [X] I am using the latest npm Current Behavior Currently observing EMFILE errors when running `npm cache verify` using npm >=8.6.0 on our Jenkins agents (EC2 instances), despite increasing `ulimit -n` from 1024 to 8192. Cannot reproduce in the same exact instance when using npm 8.5.5. Please let me know what detail might be useful to help debug this! I've collected strace output and silly-level logging. If any of that is useful, I can attempt to sanitize it to share! In the meantime, I'll likely move forward with removing the `npm cache verify` step from our Jenkins pipelines, and see if the other commands can succeed, although that will leave me with fewer warm fuzzies. [code block] [code block] Expected Behavior [code block] Steps To Reproduce 1. On our Jenkins build agents (see environment below) 2. With a particular .npm cache (I can try to make this available, upon request) 3. When using npm versions >= 8.6.0 4. Run `npm cache verify` 5. Observe EMFILE error Environment - npm: 8.6.0 and 8.7.0 - Node.js: 14.19.1 - OS Name: Amazon Linux 2 - System Model Name: - npm config: [code block] ``` $ cat /etc/*-release NAME="Amazon Linux" VERSION="2" ID="amzn" ID_LIKE="centos rhel fedora" VERSION_ID="2" PRETTY_NAME="Amazon Linux 2" ANSI_COLOR="0;33" CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2" HOME_URL="https://amazonlinux.com/" Amazon Linux relea

Error Output

error

### Environment

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Mitigate EMFILE Errors in npm Cache Verification

Medium Risk

The EMFILE error occurs when the number of file descriptors exceeds the limit set by the operating system. Although the `ulimit -n` has been increased, npm versions >= 8.6.0 may have introduced changes in how file handles are managed during cache verification, leading to this error on systems with high file handle usage.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Increase File Descriptor Limit

    Ensure that the file descriptor limit is set to a sufficiently high value. This can be done by modifying the limits in the system configuration files.

    bash
    echo 'fs.file-max = 100000' | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
  2. 2

    Modify npm Cache Verification Command

    Instead of running `npm cache verify`, consider using `npm cache clean --force` to clear the cache without verification, which may reduce the number of file handles used.

    bash
    npm cache clean --force
  3. 3

    Use npm with Increased Concurrency

    Set the npm concurrency to a lower value to reduce the number of simultaneous file operations. This can help avoid hitting the file descriptor limit.

    bash
    npm set maxsockets 5
  4. 4

    Update npm to Latest Version

    Check for any newer versions of npm that may have addressed this issue. Run the following command to update npm.

    bash
    npm install -g npm@latest
  5. 5

    Monitor File Descriptor Usage

    Use tools like `lsof` to monitor the number of open file descriptors during the cache verification process to identify if the limit is being reached.

    bash
    lsof | wc -l

Validation

After applying the above steps, run the `npm cache verify` command again to check if the EMFILE error persists. Additionally, monitor the output of `lsof` to ensure that the number of open file descriptors remains below the set limit.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

npmpackage-managernodejsrelease-8.xbugneeds-triage