Fix Zed OOM-ing when macOS file descriptors become invalid (#45669) (cherry-pick to preview) #45700
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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_worktreesand "accepted"the one with empty paths + never called
entry_iter.advance();in "nofile name found for the worktree" case, thus looping endlessly and
bloating the memory quite fast.
second
adds something that resembles a fix:
fn current_pathon macOS used thefile handler to re-fetch the worktree root file path on worktree root
canonicalization failure.
What's odd, is that
libc::fcntlreturns0in the case when externalvolume is not mounted, thus resulting in the
""path string that ispropagated 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_eventsfor 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
TODOcomment 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: