Skip to content

Commit 68ff700

Browse files
Fix process teardown deadlock on Windows (#55065) (cherry-pick to preview) (#55067)
Cherry-pick of #55065 to preview ---- AWS-LC registers an `atexit` handler that intentionally acquires a lock without releasing it. AWS-LC also has `thread_local` objects which acquire this lock in their destructor. Destructors for `thread_local`s run under the loader lock. So, there is a race condition where, if a thread exits after `atexit` handlers have run, the TLS destructors will block indefinitely on this lock while holding the loader lock. Since `ExitProcess` also requires the loader lock, process teardown will deadlock. Closes #54856 Release Notes: - Fixed an issue where the Zed process wouldn't exit after closing all windows Co-authored-by: John Tur <john-tur@outlook.com>
1 parent c8c5fd4 commit 68ff700

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

crates/gpui_windows/src/platform.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,17 @@ impl Platform for WindowsPlatform {
410410

411411
self.inner
412412
.with_callback(|callbacks| &callbacks.quit, |callback| callback());
413+
414+
// Bypass the CRT exit logic, which runs atexit handlers before calling ExitProcess.
415+
// aws-lc registers an atexit handler that intentionally acquires a lock without releasing it.
416+
// aws-lc also has thread_local objects which acquire this lock in their destructor.
417+
// Destructors for thread_locals run under the loader lock, so there is a race condition
418+
// where, if a thread exits after atexit handlers have run, the TLS destructors will block
419+
// indefinitely on this lock while holding the loader lock. Since ExitProcess also requires
420+
// the loader lock, process teardown will deadlock.
421+
unsafe {
422+
windows::Win32::System::Threading::ExitProcess(0);
423+
}
413424
}
414425

415426
fn quit(&self) {

0 commit comments

Comments
 (0)