zed
zed copied to clipboard
Unexpected Crash when performing a reopen of a "Recent Project"
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
I requested to open a "Recent Project" as shown in the below screenshot.
Zed crashed at this point
Environment
Zed: v0.119.20 (Zed) OS: macOS 14.3.0 Memory: 16 GiB Architecture: aarch64
If applicable, add mockups / screenshots to help explain present your vision of the feature
Apple Crash Report:
If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.
If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.
No response
Thanks for the crash report @wintermi
This looks like a crash we've been seeing with alacrity, the panic is on a background thread (number 46) running:
std::sys_common::backtrace::__rust_begin_short_backtrace::<<alacritty_terminal::event_loop::EventLoop<alacritty_terminal::tty::unix::Pty, terminal::ZedListener>>::spawn::{closure#0}, (alacritty_terminal::event_loop::EventLoop<alacritty_terminal::tty::unix::Pty, terminal::ZedListener>, alacritty_terminal::event_loop::State)>
cc @mrnugget
Hey @wintermi! Thanks for reporting — familiar avatar, from the Ghostty discord :) I'll try to look into this tomorrow, since I can now correlate this issue with the crash report we saw. Should probably help me reproduce it.
@wintermi can you reliably reproduce this? If so, what are the steps to reproduce this? For the life of me, I can't figure out why terminal would crash. Maybe there's something specific to your terminal setup?
I'm happy to hop on a call, btw.! I vaguely remember that we're in the same timezone.
A few more follow-up questions after digging into this a bit more:
- Just to confirm: it happens when you select the project to be opened, right? It doesn't happen when you see the dialog box to select a project?
- Does this only happen when you open Ghostty?
- How big is the terminal window before you open the recent project?
- Does this happen when you comment-out your whole shell-rc file? I'm wondering whether something in how your shell starts causes the allocated PTY to die which then causes the panic here.
On (4) and leaving some breadcrums:
I had previously assumed that between this call here
https://github.com/zed-industries/zed/blob/a0582d02b9f393ba94551d61ce6e5ffacf77760a/crates/terminal/src/terminal.rs#L341-L346
which allocates a new PTY with openpty and this call where the crash happens
https://github.com/zed-industries/zed/blob/a0582d02b9f393ba94551d61ce6e5ffacf77760a/crates/terminal/src/terminal.rs#L371
Nothing really happens except the openpty call. But now reading this again, I realise: quite a lot might happen! Because tty:new spawns the shell:
https://github.com/alacritty/alacritty/blob/7c046f5ae664f746c5f5a4bbe18c0e89f5702305/alacritty_terminal/src/tty/unix.rs#L197-L296
So my current theory is that: openpty works and succeeds, but then something goes wrong that makes the allocated master_fd of the PTY invalid, which then leads to .spawn crashing. Now we just need to figure out what goes wrong.
@wintermi can you reliably reproduce this? If so, what are the steps to reproduce this? For the life of me, I can't figure out why terminal would crash. Maybe there's something specific to your terminal setup?
I'm happy to hop on a call, btw.! I vaguely remember that we're in the same timezone.
I have not found a way to reliably reproduce the crash, in fact so far I have only experienced it 2 out 40 attempts. Both crashed after opening a Recent Project, and both crashes happened unexpectedly, while not trying to reproduce the issue. All attempts trying to reproduce the crash from a fresh start failed.
Both crashed after opening a Recent Project
Always the same project? Or a different one?
Both crashed after opening a Recent Project
Always the same project? Or a different one?
For the first crash, I was switching between 2 projects and the crash occurred after the selection of the Ghostty project. For the second crash, I was switching between 3 project and the crash did occur again on the selection of the Ghostty project.
I have however not been able to reproduce the issue since upgrading to the latest version Zed 0.119.21.
A few more follow-up questions after digging into this a bit more:
- Just to confirm: it happens when you select the project to be opened, right? It doesn't happen when you see the dialog box to select a project?
After selecting the project.
- Does this only happen when you open Ghostty?
So far, yes.
- How big is the terminal window before you open the recent project?
I never had the terminal window open on both crashes, or prior to the crash. I generally Cmd + Tab to use Ghostty.
- Does this happen when you comment-out your whole shell-rc file? I'm wondering whether something in how your shell starts causes the allocated PTY to die which then causes the panic here.
As I have not opened the terminal window, I assume that the shell is never started, or does Zed always start the shell?
I never had the terminal window open on both crashes, or prior to the crash. I generally Cmd + Tab to use Ghostty. As I have not opened the terminal window, I assume that the shell is never started, or does Zed always start the shell?
Hmmm, interesting. Zed remembers whether you had a terminal open for a given project. So if you open Ghostty in Zed, open a terminal, then close the window, then use Open recent project and select Ghostty, it should spawn with the terminal window open.
The code that caused your panic originates from the terminal-spawn code, which only gets executed when a terminal is opened. So my guess would be that when you last had the Ghostty project open, there was a terminal open, and when opening the project we restored it, which then leads to the crash.
This was fixed.