From c8e82cbd09db15ed2ba667a5f1b50b8195dbe6fb Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 8 Jun 2025 00:14:31 +0800 Subject: [PATCH] Cache connection and clear pool after all operations to avoid ObjectDisposedException --- .../ChromiumBookmarkLoader.cs | 13 +++++++++++-- .../FirefoxBookmarkLoader.cs | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs index e102e43b6..0a531f824 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs @@ -155,6 +155,9 @@ public abstract class ChromiumBookmarkLoader : IBookmarkLoader return; } + // Cache connection for pool clean + SqliteConnection connection1 = null; + try { // Since some bookmarks may have same favicon id, we need to record them to avoid duplicates @@ -216,8 +219,9 @@ public abstract class ChromiumBookmarkLoader : IBookmarkLoader } finally { - // https://github.com/dotnet/efcore/issues/26580 - SqliteConnection.ClearPool(connection); + // Cache connection and clear pool after all operations to avoid issue: + // ObjectDisposedException: Safe handle has been closed. + connection1 = connection; connection.Close(); connection.Dispose(); } @@ -231,6 +235,11 @@ public abstract class ChromiumBookmarkLoader : IBookmarkLoader // Delete temporary file try { + // https://github.com/dotnet/efcore/issues/26580 + if (connection1 != null) + { + SqliteConnection.ClearPool(connection1); + } File.Delete(tempDbPath); } catch (Exception ex) diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs index acace2506..5e4f7cbee 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs @@ -142,6 +142,9 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader return; } + // Cache connection for pool clean + SqliteConnection connection1 = null; + try { // Since some bookmarks may have same favicon id, we need to record them to avoid duplicates @@ -212,8 +215,9 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader } finally { - // https://github.com/dotnet/efcore/issues/26580 - SqliteConnection.ClearPool(connection); + // Cache connection and clear pool after all operations to avoid issue: + // ObjectDisposedException: Safe handle has been closed. + connection1 = connection; connection.Close(); connection.Dispose(); } @@ -227,6 +231,11 @@ public abstract class FirefoxBookmarkLoaderBase : IBookmarkLoader // Delete temporary file try { + // https://github.com/dotnet/efcore/issues/26580 + if (connection1 != null) + { + SqliteConnection.ClearPool(connection1); + } File.Delete(tempDbPath); } catch (Exception ex)