Commit Graph
1 Commits
Author SHA1 Message Date
Lauri Ojansivu 80c0f6875b Raise the open-file limit, so mongod does not abort mid test run.
A full Playwright run died thirteen minutes in and every spec after it
reported the same thing:

  MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:3001

which reads like the test database was never started. It was: it started at
03:03:03, said what was wrong with it in the same breath, and was ignored.

  "Soft rlimits for open file descriptors too low"
  currentValue: 256, recommendedMinimum: 64000

Thirteen minutes later it ran out:

  Error accepting new connection ... "Too many open files"
  __directory_list_worker ... journal: directory-list: opendir
  WT_PANIC: WiredTiger library panic ... the process must exit and restart
  build.sh: line 1148: 22176 Abort trap: 6   mongod --port 3001 ...

macOS starts a shell with a soft limit of 256 open files. build.sh never
raised it, so every run of the browser suites was a race between finishing and
running out of descriptors - and the failure lands 10,000 lines away in another
log, in a form that points at the wrong thing entirely.

ensure_open_files sits beside ensure_inotify_watches and runs on every
invocation, for the same reason: a limit that is too low breaks a later step
with an error that does not name it. Unlike that one it needs no root - the
hard limit is normally unlimited, so the process raises its own soft limit and
mongod, the bundle server and the browsers inherit it.

Two details, both found by running it rather than reading it:

  It sets the SOFT limit explicitly. Plain `ulimit -n` sets soft and hard, and
  lowering a hard limit is irreversible for the process - the first version
  lowered its own ceiling and could then raise nothing.

  It clamps to the hard limit and steps down from there. Asking for more than
  the hard limit fails outright rather than clamping, and macOS also caps a
  process at kern.maxfilesperproc, which the hard limit does not always
  reflect.

tests/buildScriptOpenFiles.test.cjs runs the function in shells with 256,
70000, and a 5000 hard limit, checks the opt-out, and pins both details above.

Thanks to xet7 !
2026-09-05 04:43:30 +03:00