# util: Raise open file soft limit at startup on Unix \(\#64034\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/d12e456be7c08a1dfaf21bd49ed0df1f3e2a26c6)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: d12e456be7c08a1dfaf21bd49ed0df1f3e2a26c6

Requested commit: d12e456be7c08a1dfaf21bd49ed0df1f3e2a26c6

Commit: d12e456be7c08a1dfaf21bd49ed0df1f3e2a26c6

Tree: 518bccb65a5ce31080ef39e2c1a153c3a3fef3d9

Author: Anton Wiehe

Committer: GitHub

## Message

```
util: Raise open file soft limit at startup on Unix (#64034)

# Objective

Fixes #46470
Relates to #53901, #62486, #20806

Processes launched via GUI (such as `launchd`, Finder, Spotlight, or
Dock on macOS) inherit a default soft `RLIMIT_NOFILE` of only 256 open
files (lazily raised to 2,560 by Apple frameworks on first use of
certain APIs).

In active workspaces—especially those running multiple language servers,
MCP context servers, active filesystem watchers (`FSEventStream`), and
agent tool calls—baseline file descriptor consumption sits near 200–250.
During bursts of file activity or shell tool spawning, Zed quickly
exhausts this soft limit and fails with `EMFILE (os error 24: Too many
open files)`.

Similar desktop runtimes and editors (Chromium, VS Code, Node.js, Go,
JVM) raise their soft descriptor limit at startup for this exact reason.

## Solution

- Added `util::increase_open_file_limit()` called early in `main()`
right after tracing initialization.
- On macOS, query `getrlimit(RLIMIT_NOFILE)` and raise `rlim_cur` to
`limit.rlim_max.min(OPEN_MAX)`, where `OPEN_MAX = 10,240` (from
`<sys/syslimits.h>`). Note that macOS `setrlimit(2)` returns `EINVAL` if
`rlim_cur > 10240` even when `rlim_max` is `RLIM_INFINITY`.
- On other Unix platforms (Linux), raise `rlim_cur` to
`limit.rlim_max.min(65536)`.
- If the current limit is already at or above the target, it remains
untouched.
- Added a unit test in `crates/util/src/util.rs` verifying limit
querying and retention.

## Testing

- Added `test_increase_open_file_limit` in `crates/util/src/util.rs`.
- Ran `cargo test -p util` (134 passed, 0 failed).
- Ran `cargo check -p zed` (passed cleanly).

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Raised the default open file descriptor soft limit at startup on
Unix/macOS to prevent `EMFILE` (`Too many open files`) errors in large
workspaces.

---------

Co-authored-by: Ben Kunkle <ben@zed.dev>
```

## Parents

- [7ff8e1c25875d12b4f4543415bc2a11ae67d0e9f](https://git.cafe/gitcafe/zed/commit/7ff8e1c25875d12b4f4543415bc2a11ae67d0e9f?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/d12e456be7c08a1dfaf21bd49ed0df1f3e2a26c6?format=markdown)
