Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock when resizing on Windows #3277

Open
fallenwood opened this issue Dec 27, 2024 · 9 comments
Open

Deadlock when resizing on Windows #3277

fallenwood opened this issue Dec 27, 2024 · 9 comments

Comments

@fallenwood
Copy link

When resizing on windows, the ghostty window is likely to stuck.
The stacktrace shows that it's waiting forever on BlockingQueue in MainThread, with the mutex held in push, which means it's impossible to notify the queue with pop .
Also the pop method is designed to be called on MainThread :(

Image

It's not reproducible on linux as the breakpoint set on the highlighed line never hits.

Workaround:
Instead of waiting forever, a finite wait works for me

// mailbox.zig
-                _ = mb.queue.push(msg, .{ .forever = {} });               
+                _ = mb.queue.push(msg, .{ .ns = 100 });
@mitchellh
Copy link
Contributor

Can you get me the stack traces of all threads? Its very likely this is possible on other platforms too just not happening for whatever reason and I'd like to look into it.

@fallenwood
Copy link
Author

Can you get me the stack traces of all threads? Its very likely this is possible on other platforms too just not happening for whatever reason and I'd like to look into it.

Sure, here is the full callstack of main thread

ntdll.dll!00007ffa67063374() (Unknown Source:0)
ntdll.dll!00007ffa66f5f574() (Unknown Source:0)
KernelBase.dll!00007ffa6455d8f8() (Unknown Source:0)
ghostty.exe!wait(builtin.StackTrace * self, Thread.Condition.WindowsImpl * mutex, Thread.Mutex * timeout, ?u64 *) Line 168 (c:\Programs\zig\lib\std\Thread\Condition.zig:168)
ghostty.exe!wait(Thread.Condition * self, Thread.Mutex * mutex) Line 72 (c:\Programs\zig\lib\std\Thread\Condition.zig:72)
ghostty.exe!push(datastruct.blocking_queue.BlockingQueue(termio.message.Message,64) * self, termio.message.Message * value, datastruct.blocking_queue.BlockingQueue(App.Message,64).Timeout * timeout) Line 116 (d:\Workspace\ghostty\src\datastruct\blocking_queue.zig:116)
ghostty.exe!send(termio.mailbox.Mailbox * self, termio.message.Message * msg, Thread.Mutex * mutex) Line 94 (d:\Workspace\ghostty\src\termio\mailbox.zig:94)
ghostty.exe!queueMessage(termio.Termio * self, termio.message.Message * msg, termio.Termio.queueMessage__enum_67818 mutex) Line 278 (d:\Workspace\ghostty\src\termio\Termio.zig:278)
ghostty.exe!resize(builtin.StackTrace * self, Surface * size, renderer.size.ScreenSize *) Line 1554 (d:\Workspace\ghostty\src\Surface.zig:1554)
ghostty.exe!sizeCallback(builtin.StackTrace * self, Surface * size, apprt.structs.SurfaceSize *) Line 1519 (d:\Workspace\ghostty\src\Surface.zig:1519)
[Inline Frame] ghostty.exe!sizeCallback() Line 863 (d:\Workspace\ghostty\src\apprt\glfw.zig:863)
ghostty.exe!sizeCallbackWrapper(cimport.struct_GLFWwindow * handle, int width, int height) Line 1270 (c:\Users\<username>\AppData\Local\zig\p\12206ed982e709e565d536ce930701a8c07edfd2cfdce428683f3f2a601d37696a62\src\Window.zig:1270)
ghostty.exe!_glfwInputWindowSize(_GLFWwindow * window, int width, int height) Line 96 (c:\Users\<username>\AppData\Local\zig\p\1220736fa4ba211162c7a0e46cc8fe04d95921927688bff64ab5da7420d098a7272d\src\window.c:96)
ghostty.exe!windowProc(HWND__ * hWnd, unsigned int uMsg, unsigned __int64 wParam, __int64 lParam) Line 1027 (c:\Users\<username>\AppData\Local\zig\p\1220736fa4ba211162c7a0e46cc8fe04d95921927688bff64ab5da7420d098a7272d\src\win32_window.c:1027)
user32.dll!00007ffa651b5801() (Unknown Source:0)
user32.dll!00007ffa651b52dc() (Unknown Source:0)
opengl32.dll!00007ffa2429bcf3() (Unknown Source:0)
user32.dll!00007ffa651b5801() (Unknown Source:0)
user32.dll!00007ffa651b509c() (Unknown Source:0)
user32.dll!00007ffa651e4eb3() (Unknown Source:0)
ntdll.dll!00007ffa67063744() (Unknown Source:0)
win32u.dll!00007ffa64451334() (Unknown Source:0)
user32.dll!00007ffa651b4c82() (Unknown Source:0)
user32.dll!00007ffa651b1dcf() (Unknown Source:0)
user32.dll!00007ffa651b1a54() (Unknown Source:0)
uxtheme.dll!00007ffa5e152c64() (Unknown Source:0)
uxtheme.dll!00007ffa5e152bb1() (Unknown Source:0)
user32.dll!00007ffa651b30aa() (Unknown Source:0)
ghostty.exe!windowProc(HWND__ * hWnd, unsigned int uMsg, unsigned __int64 wParam, __int64 lParam) Line 1247 (c:\Users\<username>\AppData\Local\zig\p\1220736fa4ba211162c7a0e46cc8fe04d95921927688bff64ab5da7420d098a7272d\src\win32_window.c:1247)
user32.dll!00007ffa651b5801() (Unknown Source:0)
user32.dll!00007ffa651b52dc() (Unknown Source:0)
opengl32.dll!00007ffa2429bcf3() (Unknown Source:0)
user32.dll!00007ffa651b5801() (Unknown Source:0)
user32.dll!00007ffa651b509c() (Unknown Source:0)
user32.dll!00007ffa651f0cf3() (Unknown Source:0)
ntdll.dll!00007ffa67063744() (Unknown Source:0)
win32u.dll!00007ffa64451334() (Unknown Source:0)
user32.dll!00007ffa651b1bbb() (Unknown Source:0)
user32.dll!00007ffa651b1a54() (Unknown Source:0)
uxtheme.dll!00007ffa5e15138d() (Unknown Source:0)
uxtheme.dll!00007ffa5e14f45a() (Unknown Source:0)
uxtheme.dll!00007ffa5e15331f() (Unknown Source:0)
uxtheme.dll!00007ffa5e152bb1() (Unknown Source:0)
user32.dll!00007ffa651b30aa() (Unknown Source:0)
ghostty.exe!windowProc(HWND__ * hWnd, unsigned int uMsg, unsigned __int64 wParam, __int64 lParam) Line 1247 (c:\Users\<username>\AppData\Local\zig\p\1220736fa4ba211162c7a0e46cc8fe04d95921927688bff64ab5da7420d098a7272d\src\win32_window.c:1247)
user32.dll!00007ffa651b5801() (Unknown Source:0)
user32.dll!00007ffa651b52dc() (Unknown Source:0)
opengl32.dll!00007ffa2429bcf3() (Unknown Source:0)
user32.dll!00007ffa651b5801() (Unknown Source:0)
user32.dll!00007ffa651b509c() (Unknown Source:0)
user32.dll!00007ffa651e4eb3() (Unknown Source:0)
ntdll.dll!00007ffa67063744() (Unknown Source:0)
win32u.dll!00007ffa64451334() (Unknown Source:0)
user32.dll!00007ffa651b1bbb() (Unknown Source:0)
user32.dll!00007ffa651b1a54() (Unknown Source:0)
uxtheme.dll!00007ffa5e15138d() (Unknown Source:0)
uxtheme.dll!00007ffa5e189919() (Unknown Source:0)
uxtheme.dll!00007ffa5e15331f() (Unknown Source:0)
uxtheme.dll!00007ffa5e152bb1() (Unknown Source:0)
user32.dll!00007ffa651b30aa() (Unknown Source:0)
ghostty.exe!windowProc(HWND__ * hWnd, unsigned int uMsg, unsigned __int64 wParam, __int64 lParam) Line 1247 (c:\Users\<username>\AppData\Local\zig\p\1220736fa4ba211162c7a0e46cc8fe04d95921927688bff64ab5da7420d098a7272d\src\win32_window.c:1247)
user32.dll!00007ffa651b5801() (Unknown Source:0)
user32.dll!00007ffa651b52dc() (Unknown Source:0)
opengl32.dll!00007ffa2429bcf3() (Unknown Source:0)
user32.dll!00007ffa651b5801() (Unknown Source:0)
user32.dll!00007ffa651b334d() (Unknown Source:0)
ghostty.exe!_glfwPollEventsWin32() Line 2039 (c:\Users\<username>\AppData\Local\zig\p\1220736fa4ba211162c7a0e46cc8fe04d95921927688bff64ab5da7420d098a7272d\src\win32_window.c:2039)
ghostty.exe!_glfwWaitEventsWin32() Line 2120 (c:\Users\<username>\AppData\Local\zig\p\1220736fa4ba211162c7a0e46cc8fe04d95921927688bff64ab5da7420d098a7272d\src\win32_window.c:2120)
ghostty.exe!glfwWaitEvents() Line 1132 (c:\Users\<username>\AppData\Local\zig\p\1220736fa4ba211162c7a0e46cc8fe04d95921927688bff64ab5da7420d098a7272d\src\window.c:1132)
[Inline Frame] ghostty.exe!waitEvents() Line 427 (c:\Users\<username>\AppData\Local\zig\p\12206ed982e709e565d536ce930701a8c07edfd2cfdce428683f3f2a601d37696a62\src\main.zig:427)
ghostty.exe!run(builtin.StackTrace * self, apprt.glfw.App *) Line 124 (d:\Workspace\ghostty\src\apprt\glfw.zig:124)
ghostty.exe!main(builtin.StackTrace *) Line 111 (d:\Workspace\ghostty\src\main_ghostty.zig:111)
[Inline Frame] ghostty.exe!callMain() Line 524 (c:\Programs\zig\lib\std\start.zig:524)
[Inline Frame] ghostty.exe!callMainWithArgs() Line 482 (c:\Programs\zig\lib\std\start.zig:482)
ghostty.exe!main(int c_argc, char * * c_argv, char * * c_envp) Line 497 (c:\Programs\zig\lib\std\start.zig:497)
ghostty.exe!__tmainCRTStartup() Line 267 (c:\Programs\zig\lib\libc\mingw\crt\crtexe.c:267)
ghostty.exe!WinMainCRTStartup() Line 159 (c:\Programs\zig\lib\libc\mingw\crt\crtexe.c:159)
kernel32.dll!00007ffa65e2e8d7() (Unknown Source:0)
ntdll.dll!00007ffa66fdfbcc() (Unknown Source:0)

@mitchellh
Copy link
Contributor

Sorry I meant all threads. Can you get me the stacks of all threads? I want to see what the rest are doing.

@fallenwood
Copy link
Author

Sorry I meant all threads. Can you get me the stacks of all threads? I want to see what the rest are doing.

Ah my bad, here are the callstacks

ghostty_callstacks.zip

@fallenwood
Copy link
Author

fallenwood commented Dec 27, 2024

After reading deeper into the source, I found the wakeupCallback in renderer/Thread.zig is not called (the break point not hit), while self.wakeup.wait(&self.loop, &self.wakeup_c, Thread, self, wakeupCallback); did called.

It also lead to a crash that, after resizing, left click the area newlly created, the app crashed for Debug build at Surface.zig

        const pin = pin: {
            const pt_viewport = self.posToViewport(pos.x, pos.y);
            const pin = screen.pages.pin(.{
                .viewport = .{
                    .x = pt_viewport.x,
                    .y = pt_viewport.y,
                },
            }) orelse {
                // Weird... our viewport x/y that we just converted isn't
                // found in our pages. This is probably a bug but we don't
                // want to crash in releases because its harmless. So, we
                // only assert in debug mode.
                if (comptime std.debug.runtime_safety) unreachable;  <--------------------
                break :click;
            };

            break :pin try screen.pages.trackPin(pin);
        };

Also I believe that's why there is nothing show from cmd.exe in the terminal window


It blocks on, and there is nothing show in ghostty window

Image

    // Start blinking the cursor.
    self.cursor_h.run(
        &self.loop,
        &self.cursor_c,
        CURSOR_BLINK_INTERVAL,
        Thread,
        self,
        cursorTimerCallback,
    );

@gaocegege
Copy link

I’m not entirely sure if this is the right place to ask, but I’m wondering how to get Ghostty on Windows. I couldn’t find any information about it in the documentation or on the download page. Could someone point me in the right direction?

@fallenwood
Copy link
Author

I’m not entirely sure if this is the right place to ask, but I’m wondering how to get Ghostty on Windows. I couldn’t find any information about it in the documentation or on the download page. Could someone point me in the right direction?

just build from source with zig 0.13, either natively on windows or cross build from linux
but as you can see from the screenshot, it does not work now, lots of bugs need to fix

@melutovich
Copy link

@gaocegege The github readme in the Roadmap says Windows support is not yet done
#2563

@mitchellh
Copy link
Contributor

Yes, if this is a Windows-only issue I will close it. But if this deadlock can potentially impact other platforms I need to look into it. That's why I've kept this open until that's verified.

Corendos added a commit to Corendos/ghostty that referenced this issue Jan 7, 2025
We were using `opts.backend` for which `initTerminal` was not called.
This lead to the PTY being created with a size of (0, 0), making the
`CreatePseudoConsole` to fail, then making the IO thread to exit early.

This was the cause of the hang observed in ghostty-org#3277.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants