Vitest failing in gitlab runners of inotify.max_user_watches exhaustion

557 Views Asked by At

Our test started failing after adding some additional node modules

excerpt from the shared gitlab runner log

yarn run v1.22.19
$ vitest --run --watch=false --reporter junit
[ESLint] Found 0 error and 0 warning
node:internal/event_target:1037
  process.nextTick(() => { throw err; });
                           ^
Error: ENOSPC: System limit for number of file watchers reached, watch '/builds/project/src'
    at FSWatcher.<computed> (node:internal/fs/watchers:247:19)
    at Object.watch (node:fs:2399:36)
    at createFsWatchInstance (/builds/project/node_modules/chokidar/lib/nodefs-handler.js:119:15)
    at setFsWatchListener (/builds/project/node_modules/chokidar/lib/nodefs-handler.js:166:15)
    at NodeFsHandler._watchWithNodeFs (/builds/project/node_modules/chokidar/lib/nodefs-handler.js:331:14)
    at NodeFsHandler._handleDir (/builds/project/node_modules/chokidar/lib/nodefs-handler.js:567:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async NodeFsHandler._addToNodeFs (/builds/project/node_modules/chokidar/lib/nodefs-handler.js:617:16)
    at async /builds/project/node_modules/chokidar/index.js:451:21
    at async Promise.all (index 0)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:323:10)
    at [kOnMessage] (node:internal/worker:334:37)
    at MessagePort.<anonymous> (node:internal/worker:229:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:762:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28) {
  errno: -28,
  syscall: 'watch',
  code: 'ENOSPC',
  path: '/builds/project/src',
  filename: '/builds/project/src'
}
Node.js v20.1.0

The cause is inotify.max_user_watches exhaustion on the shared gitlab runner, this is set to 8192 and since the number of files and folder in the node modules folder is 16k+ this causes the exception.

This is easily reproducible in a vm by setting the inotify.max_user_watches to the same value as in the runner.

What I'm curious about is if this is expected behavior when running in a non-watch mode?

1

There are 1 best solutions below

0
Stefan A.Svellingen On

I posted this over at the vitest github discussion and I got an answer that did solve the issue for us by setting CHOKIDAR_USEPOLLING=1 before running vitest

Vitest failing in gitlab runners