From 6edc563cf9ca26b4622c3135d92e493a5d5bd6e8 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Thu, 22 Feb 2024 22:02:13 -0300 Subject: [PATCH] fix(core): deadlock on window destroy (#8953) --- .changes/fix-window-destroy-deadlock.md | 5 +++++ core/tauri/src/manager/mod.rs | 3 ++- core/tauri/src/webview/mod.rs | 4 ++++ core/tauri/src/window/mod.rs | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changes/fix-window-destroy-deadlock.md diff --git a/.changes/fix-window-destroy-deadlock.md b/.changes/fix-window-destroy-deadlock.md new file mode 100644 index 000000000..014ca46c1 --- /dev/null +++ b/.changes/fix-window-destroy-deadlock.md @@ -0,0 +1,5 @@ +--- +"tauri": patch:bug +--- + +Fixes a deadlock when the window is destroyed. diff --git a/core/tauri/src/manager/mod.rs b/core/tauri/src/manager/mod.rs index 026638dd3..914390916 100644 --- a/core/tauri/src/manager/mod.rs +++ b/core/tauri/src/manager/mod.rs @@ -528,7 +528,8 @@ impl AppManager { } pub(crate) fn on_window_close(&self, label: &str) { - if let Some(window) = self.window.windows_lock().remove(label) { + let window = self.window.windows_lock().remove(label); + if let Some(window) = window { for webview in window.webviews() { self.webview.webviews_lock().remove(webview.label()); } diff --git a/core/tauri/src/webview/mod.rs b/core/tauri/src/webview/mod.rs index cc0b673d7..2e4bafe9e 100644 --- a/core/tauri/src/webview/mod.rs +++ b/core/tauri/src/webview/mod.rs @@ -979,6 +979,10 @@ impl Webview { .expect("could not locate webview parent window") } + pub(crate) fn window_label(&self) -> String { + self.window_label.lock().unwrap().clone() + } + /// Executes a closure, providing it with the webview handle that is specific to the current platform. /// /// The closure is executed on the main thread. diff --git a/core/tauri/src/window/mod.rs b/core/tauri/src/window/mod.rs index e83998317..dc7e37d36 100644 --- a/core/tauri/src/window/mod.rs +++ b/core/tauri/src/window/mod.rs @@ -988,7 +988,7 @@ impl Window { .webview .webviews_lock() .values() - .filter(|w| &w.window() == self) + .filter(|w| w.window_label() == self.label()) .cloned() .collect() }