Skip to content

Fix LSP thread hang on exit on Windows#6196

Merged
aryairani merged 9 commits intounisonweb:trunkfrom
andgate:fix/windows-lsp-exit-hang
Mar 30, 2026
Merged

Fix LSP thread hang on exit on Windows#6196
aryairani merged 9 commits intounisonweb:trunkfrom
andgate:fix/windows-lsp-exit-hang

Conversation

@andgate
Copy link
Copy Markdown

@andgate andgate commented Mar 19, 2026

Fixes #3487

Problem

On Windows, typing exit or quit in a UCM shell session would cause the terminal to hang, requiring a manual Ctrl+C to kill the process. This was caused by the GHC Windows I/O manager being unable to deliver async exceptions to threads blocked in a socket accept call. When the UCM CLI exited, Ki.scoped would try to cancel and join the LSP thread, but the LSP thread was blocked in TCP.serve waiting for a connection and would never wake up.

As a workaround, the LSP was disabled by default on Windows behind a UNISON_LSP_ENABLED=true environment variable flag.

Fix

Instead of using TCP.serve (which owns the socket internally), we now manually bind the socket with TCP.bindSock so we can hold a reference to it. The socket is passed back to Main.hs via a callback. After the UCM CLI exits, Main.hs closes the socket, which unblocks the accept call at the OS level and allows the LSP thread to exit cleanly on all platforms.

A shutdownVar flag is set before the accept loop starts. When handleFailure catches an IOException during shutdown, it checks this flag and suppresses the misleading "LSP server failed to start" message. All other error cases should be unaffected, since only IOException is caught here, and only the error message is suppressed, not any other behavior.

With the exit hang fixed, the UNISON_LSP_ENABLED Windows guard in ifEnabled has been removed, enabling LSP on Windows by default.

Result

UCM now exits cleanly on Windows without hanging, and the LSP server starts by default on Windows, allowing the VS Code extension to connect without any additional configuration.

@aryairani aryairani requested a review from a team as a code owner March 30, 2026 03:29
@aryairani aryairani added this pull request to the merge queue Mar 30, 2026
@aryairani aryairani removed this pull request from the merge queue due to a manual request Mar 30, 2026
@aryairani aryairani enabled auto-merge March 30, 2026 04:08
@aryairani aryairani disabled auto-merge March 30, 2026 04:08
@aryairani aryairani added this pull request to the merge queue Mar 30, 2026
Merged via the queue into unisonweb:trunk with commit 89ec4f2 Mar 30, 2026
8 checks passed
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

Successfully merging this pull request may close these issues.

Error trying to use vscode extension in windows 10

2 participants