Skip to content

Fix Zed OOM-ing when macOS file descriptors become invalid#45669

Merged
SomeoneToIgnore merged 3 commits intomainfrom
kb/oooooooooooooooooooooom
Dec 26, 2025
Merged

Fix Zed OOM-ing when macOS file descriptors become invalid#45669
SomeoneToIgnore merged 3 commits intomainfrom
kb/oooooooooooooooooooooom

Conversation

@SomeoneToIgnore
Copy link
Contributor

@SomeoneToIgnore SomeoneToIgnore commented Dec 25, 2025

Closes #42845

Repro steps: #42845 (comment)
Initial investigation and Zed memory trace: #42845 (comment)

The PR consists of 2 commits:

  • first adds cosmetic fixes to remove backtraces from logs yet again and print paths in quotes, as file descriptors may return empty paths.
    It also stubs the cause if OOM in project panel: that one traversed all worktrees in for worktree_snapshot in visible_worktrees and "accepted" the one with empty paths + never called entry_iter.advance(); in "no file name found for the worktree" case, thus looping endlessly and bloating the memory quite fast.

  • second adds something that resembles a fix: fn current_path on macOS used the file handler to re-fetch the worktree root file path on worktree root canonicalization failure.
    What's odd, is that libc::fcntl returns 0 in the case when external volume is not mounted, thus resulting in the "" path string that is propagated all the way up.

  • third moves the fix down to the platform-related FS implementations

The "fix" now checks the only usage of this method inside async fn process_events for an empty path and bails if that is the case.
I am not sure what is a better fix, but this stops any memory leaks and given how bad the situation now, seems ok to merge for now with the TODO comment for more clever people to fix properly later.


Now, when I disconnect the SMB share and reconnect it again, Zed stops displaying any files in the project tree but the ones opened as editors.

As before, at first, when the share is unmounted, Zed fails to save any changes because of the timeouts.

Later, when the share is re-connected, macOS Finder hangs still but Zed starts to react on saves yet still only shows the files that are open as editors.
The files can be edited and saved from now on.

Later, when Finder finally stops hanging and indicates that the share is mounted fully, the rest of the file structure reappear in the project panel, and all file saves are propagated, hence can be observed in the share in Finder.

It feels that one good improvement to add on top is some "disconnected" indicator that clearly shows that the file is not properly handles in the OS.
This requires much more changes and thinking as nothing like that exists in Zed yet, hence not done.

Release Notes:

  • Fixed Zed OOM-ing when macOS file descriptors become invalid

@SomeoneToIgnore SomeoneToIgnore added the run-bundling Configures PR to run the bundle step label Dec 25, 2025
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 25, 2025
@zed-industries-bot

This comment was marked as resolved.

@SomeoneToIgnore SomeoneToIgnore changed the title Ignore Fix Zed OOM-ing when macOS file descriptors become invalid Dec 25, 2025
@SomeoneToIgnore SomeoneToIgnore self-assigned this Dec 25, 2025
@SomeoneToIgnore
Copy link
Contributor Author

Have tested both Windows and Linux and in my test case, they have never timed out the save when the disconnect happened.
On SMB reconnect, the save finished.

This means that no such OOM is possible technically, but I've added similar checks to Windows and FreeBSD code.

@SomeoneToIgnore SomeoneToIgnore enabled auto-merge (squash) December 26, 2025 18:36
@SomeoneToIgnore SomeoneToIgnore removed the run-bundling Configures PR to run the bundle step label Dec 26, 2025
@SomeoneToIgnore SomeoneToIgnore force-pushed the kb/oooooooooooooooooooooom branch from c74cf43 to 1a7560c Compare December 26, 2025 18:37
@SomeoneToIgnore SomeoneToIgnore enabled auto-merge (squash) December 26, 2025 18:38
@SomeoneToIgnore SomeoneToIgnore merged commit a50c5b2 into main Dec 26, 2025
24 checks passed
@SomeoneToIgnore SomeoneToIgnore deleted the kb/oooooooooooooooooooooom branch December 26, 2025 18:47
@SomeoneToIgnore
Copy link
Contributor Author

/cherry-pick preview

github-actions bot pushed a commit that referenced this pull request Dec 26, 2025
Closes #42845

Repro steps:
#42845 (comment)
Initial investigation and Zed memory trace:
#42845 (comment)

The PR consists of 2 commits:
*
[first](732d308)
adds cosmetic fixes to remove backtraces from logs yet again and print
paths in quotes, as file descriptors may return empty paths.
It also stubs the cause if OOM in project panel: that one traversed all
worktrees in `for worktree_snapshot in visible_worktrees` and "accepted"
the one with empty paths + never called `entry_iter.advance();` in "no
file name found for the worktree" case, thus looping endlessly and
bloating the memory quite fast.

*
[second](7ebfe5d)
adds something that resembles a fix: `fn current_path` on macOS used the
file handler to re-fetch the worktree root file path on worktree root
canonicalization failure.
What's odd, is that `libc::fcntl` returns `0` in the case when external
volume is not mounted, thus resulting in the `""` path string that is
propagated all the way up.

*
[third](1a7560c)
moves the fix down to the platform-related FS implementations

The "fix" now checks the only usage of this method inside `async fn
process_events` for an empty path and bails if that is the case.
I am not sure what is a better fix, but this stops any memory leaks and
given how bad the situation now, seems ok to merge for now with the
`TODO` comment for more clever people to fix properly later.

----------------

Now, when I disconnect the SMB share and reconnect it again, Zed stops
displaying any files in the project tree but the ones opened as editors.

As before, at first, when the share is unmounted, Zed fails to save any
changes because of the timeouts.

Later, when the share is re-connected, macOS Finder hangs still but Zed
starts to react on saves yet still only shows the files that are open as
editors.
The files can be edited and saved from now on.

Later, when Finder finally stops hanging and indicates that the share is
mounted fully, the rest of the file structure reappear in the project
panel, and all file saves are propagated, hence can be observed in the
share in Finder.

It feels that one good improvement to add on top is some "disconnected"
indicator that clearly shows that the file is not properly handles in
the OS.
This requires much more changes and thinking as nothing like that exists
in Zed yet, hence not done.

Release Notes:

- Fixed Zed OOM-ing when macOS file descriptors become invalid
zed-zippy bot added a commit that referenced this pull request Dec 26, 2025
…cherry-pick to preview) (#45700)

Cherry-pick of #45669 to preview

----
Closes #42845

Repro steps:

#42845 (comment)
Initial investigation and Zed memory trace:

#42845 (comment)

The PR consists of 2 commits:
*

[first](732d308)
adds cosmetic fixes to remove backtraces from logs yet again and print
paths in quotes, as file descriptors may return empty paths.
It also stubs the cause if OOM in project panel: that one traversed all
worktrees in `for worktree_snapshot in visible_worktrees` and "accepted"
the one with empty paths + never called `entry_iter.advance();` in "no
file name found for the worktree" case, thus looping endlessly and
bloating the memory quite fast.

*

[second](7ebfe5d)
adds something that resembles a fix: `fn current_path` on macOS used the
file handler to re-fetch the worktree root file path on worktree root
canonicalization failure.
What's odd, is that `libc::fcntl` returns `0` in the case when external
volume is not mounted, thus resulting in the `""` path string that is
propagated all the way up.

*

[third](1a7560c)
moves the fix down to the platform-related FS implementations

The "fix" now checks the only usage of this method inside `async fn
process_events` for an empty path and bails if that is the case.
I am not sure what is a better fix, but this stops any memory leaks and
given how bad the situation now, seems ok to merge for now with the
`TODO` comment for more clever people to fix properly later.

----------------

Now, when I disconnect the SMB share and reconnect it again, Zed stops
displaying any files in the project tree but the ones opened as editors.

As before, at first, when the share is unmounted, Zed fails to save any
changes because of the timeouts.

Later, when the share is re-connected, macOS Finder hangs still but Zed
starts to react on saves yet still only shows the files that are open as
editors.
The files can be edited and saved from now on.

Later, when Finder finally stops hanging and indicates that the share is
mounted fully, the rest of the file structure reappear in the project
panel, and all file saves are propagated, hence can be observed in the
share in Finder.

It feels that one good improvement to add on top is some "disconnected"
indicator that clearly shows that the file is not properly handles in
the OS.
This requires much more changes and thinking as nothing like that exists
in Zed yet, hence not done.

Release Notes:

- Fixed Zed OOM-ing when macOS file descriptors become invalid

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
@nikivdev
Copy link

Thank you lots for this PR, this issue is blocking me hard now.

How can I get your change quickly, can I get zed next and that will have this commit?

Or I have to rebuild from source tree myself?

Thank you.

@SomeoneToIgnore
Copy link
Contributor Author

This is supposed to be released next Wednesday to both Preview and Stable, which is only 4 days away.

CherryWorm pushed a commit to CherryWorm/zed that referenced this pull request Dec 30, 2025
…tries#45669)

Closes zed-industries#42845

Repro steps:
zed-industries#42845 (comment)
Initial investigation and Zed memory trace:
zed-industries#42845 (comment)

The PR consists of 2 commits:
*
[first](zed-industries@732d308)
adds cosmetic fixes to remove backtraces from logs yet again and print
paths in quotes, as file descriptors may return empty paths.
It also stubs the cause if OOM in project panel: that one traversed all
worktrees in `for worktree_snapshot in visible_worktrees` and "accepted"
the one with empty paths + never called `entry_iter.advance();` in "no
file name found for the worktree" case, thus looping endlessly and
bloating the memory quite fast.

*
[second](zed-industries@7ebfe5d)
adds something that resembles a fix: `fn current_path` on macOS used the
file handler to re-fetch the worktree root file path on worktree root
canonicalization failure.
What's odd, is that `libc::fcntl` returns `0` in the case when external
volume is not mounted, thus resulting in the `""` path string that is
propagated all the way up.

*
[third](zed-industries@1a7560c)
moves the fix down to the platform-related FS implementations

The "fix" now checks the only usage of this method inside `async fn
process_events` for an empty path and bails if that is the case.
I am not sure what is a better fix, but this stops any memory leaks and
given how bad the situation now, seems ok to merge for now with the
`TODO` comment for more clever people to fix properly later.

----------------

Now, when I disconnect the SMB share and reconnect it again, Zed stops
displaying any files in the project tree but the ones opened as editors.

As before, at first, when the share is unmounted, Zed fails to save any
changes because of the timeouts.

Later, when the share is re-connected, macOS Finder hangs still but Zed
starts to react on saves yet still only shows the files that are open as
editors.
The files can be edited and saved from now on.

Later, when Finder finally stops hanging and indicates that the share is
mounted fully, the rest of the file structure reappear in the project
panel, and all file saves are propagated, hence can be observed in the
share in Finder.

It feels that one good improvement to add on top is some "disconnected"
indicator that clearly shows that the file is not properly handles in
the OS.
This requires much more changes and thinking as nothing like that exists
in Zed yet, hence not done.

Release Notes:

- Fixed Zed OOM-ing when macOS file descriptors become invalid
rtfeldman pushed a commit that referenced this pull request Jan 5, 2026
Closes #42845

Repro steps:
#42845 (comment)
Initial investigation and Zed memory trace:
#42845 (comment)

The PR consists of 2 commits:
*
[first](732d308)
adds cosmetic fixes to remove backtraces from logs yet again and print
paths in quotes, as file descriptors may return empty paths.
It also stubs the cause if OOM in project panel: that one traversed all
worktrees in `for worktree_snapshot in visible_worktrees` and "accepted"
the one with empty paths + never called `entry_iter.advance();` in "no
file name found for the worktree" case, thus looping endlessly and
bloating the memory quite fast.

*
[second](7ebfe5d)
adds something that resembles a fix: `fn current_path` on macOS used the
file handler to re-fetch the worktree root file path on worktree root
canonicalization failure.
What's odd, is that `libc::fcntl` returns `0` in the case when external
volume is not mounted, thus resulting in the `""` path string that is
propagated all the way up.

*
[third](1a7560c)
moves the fix down to the platform-related FS implementations

The "fix" now checks the only usage of this method inside `async fn
process_events` for an empty path and bails if that is the case.
I am not sure what is a better fix, but this stops any memory leaks and
given how bad the situation now, seems ok to merge for now with the
`TODO` comment for more clever people to fix properly later.

----------------

Now, when I disconnect the SMB share and reconnect it again, Zed stops
displaying any files in the project tree but the ones opened as editors.

As before, at first, when the share is unmounted, Zed fails to save any
changes because of the timeouts.

Later, when the share is re-connected, macOS Finder hangs still but Zed
starts to react on saves yet still only shows the files that are open as
editors.
The files can be edited and saved from now on.

Later, when Finder finally stops hanging and indicates that the share is
mounted fully, the rest of the file structure reappear in the project
panel, and all file saves are propagated, hence can be observed in the
share in Finder.

It feels that one good improvement to add on top is some "disconnected"
indicator that clearly shows that the file is not properly handles in
the OS.
This requires much more changes and thinking as nothing like that exists
in Zed yet, hence not done.

Release Notes:

- Fixed Zed OOM-ing when macOS file descriptors become invalid
LivioGama pushed a commit to LivioGama/zed that referenced this pull request Jan 20, 2026
…tries#45669)

Closes zed-industries#42845

Repro steps:
zed-industries#42845 (comment)
Initial investigation and Zed memory trace:
zed-industries#42845 (comment)

The PR consists of 2 commits:
*
[first](zed-industries@732d308)
adds cosmetic fixes to remove backtraces from logs yet again and print
paths in quotes, as file descriptors may return empty paths.
It also stubs the cause if OOM in project panel: that one traversed all
worktrees in `for worktree_snapshot in visible_worktrees` and "accepted"
the one with empty paths + never called `entry_iter.advance();` in "no
file name found for the worktree" case, thus looping endlessly and
bloating the memory quite fast.

*
[second](zed-industries@7ebfe5d)
adds something that resembles a fix: `fn current_path` on macOS used the
file handler to re-fetch the worktree root file path on worktree root
canonicalization failure.
What's odd, is that `libc::fcntl` returns `0` in the case when external
volume is not mounted, thus resulting in the `""` path string that is
propagated all the way up.

*
[third](zed-industries@1a7560c)
moves the fix down to the platform-related FS implementations

The "fix" now checks the only usage of this method inside `async fn
process_events` for an empty path and bails if that is the case.
I am not sure what is a better fix, but this stops any memory leaks and
given how bad the situation now, seems ok to merge for now with the
`TODO` comment for more clever people to fix properly later.

----------------

Now, when I disconnect the SMB share and reconnect it again, Zed stops
displaying any files in the project tree but the ones opened as editors.

As before, at first, when the share is unmounted, Zed fails to save any
changes because of the timeouts.

Later, when the share is re-connected, macOS Finder hangs still but Zed
starts to react on saves yet still only shows the files that are open as
editors.
The files can be edited and saved from now on.

Later, when Finder finally stops hanging and indicates that the share is
mounted fully, the rest of the file structure reappear in the project
panel, and all file saves are propagated, hence can be observed in the
share in Finder.

It feels that one good improvement to add on top is some "disconnected"
indicator that clearly shows that the file is not properly handles in
the OS.
This requires much more changes and thinking as nothing like that exists
in Zed yet, hence not done.

Release Notes:

- Fixed Zed OOM-ing when macOS file descriptors become invalid
LivioGama pushed a commit to LivioGama/zed that referenced this pull request Jan 20, 2026
…tries#45669)

Closes zed-industries#42845

Repro steps:
zed-industries#42845 (comment)
Initial investigation and Zed memory trace:
zed-industries#42845 (comment)

The PR consists of 2 commits:
*
[first](zed-industries@732d308)
adds cosmetic fixes to remove backtraces from logs yet again and print
paths in quotes, as file descriptors may return empty paths.
It also stubs the cause if OOM in project panel: that one traversed all
worktrees in `for worktree_snapshot in visible_worktrees` and "accepted"
the one with empty paths + never called `entry_iter.advance();` in "no
file name found for the worktree" case, thus looping endlessly and
bloating the memory quite fast.

*
[second](zed-industries@7ebfe5d)
adds something that resembles a fix: `fn current_path` on macOS used the
file handler to re-fetch the worktree root file path on worktree root
canonicalization failure.
What's odd, is that `libc::fcntl` returns `0` in the case when external
volume is not mounted, thus resulting in the `""` path string that is
propagated all the way up.

*
[third](zed-industries@1a7560c)
moves the fix down to the platform-related FS implementations

The "fix" now checks the only usage of this method inside `async fn
process_events` for an empty path and bails if that is the case.
I am not sure what is a better fix, but this stops any memory leaks and
given how bad the situation now, seems ok to merge for now with the
`TODO` comment for more clever people to fix properly later.

----------------

Now, when I disconnect the SMB share and reconnect it again, Zed stops
displaying any files in the project tree but the ones opened as editors.

As before, at first, when the share is unmounted, Zed fails to save any
changes because of the timeouts.

Later, when the share is re-connected, macOS Finder hangs still but Zed
starts to react on saves yet still only shows the files that are open as
editors.
The files can be edited and saved from now on.

Later, when Finder finally stops hanging and indicates that the share is
mounted fully, the rest of the file structure reappear in the project
panel, and all file saves are propagated, hence can be observed in the
share in Finder.

It feels that one good improvement to add on top is some "disconnected"
indicator that clearly shows that the file is not properly handles in
the OS.
This requires much more changes and thinking as nothing like that exists
in Zed yet, hence not done.

Release Notes:

- Fixed Zed OOM-ing when macOS file descriptors become invalid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zed Using > 53GB of Application Memory

3 participants