Skip to content

Commit c8e82cb

Browse files
committed
Cache connection and clear pool after all operations to avoid ObjectDisposedException
1 parent 2a4b4de commit c8e82cb

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ private void LoadFaviconsFromDb(string dbPath, List<Bookmark> bookmarks)
155155
return;
156156
}
157157

158+
// Cache connection for pool clean
159+
SqliteConnection connection1 = null;
160+
158161
try
159162
{
160163
// Since some bookmarks may have same favicon id, we need to record them to avoid duplicates
@@ -216,8 +219,9 @@ ORDER BY b.width DESC
216219
}
217220
finally
218221
{
219-
// https://github.com/dotnet/efcore/issues/26580
220-
SqliteConnection.ClearPool(connection);
222+
// Cache connection and clear pool after all operations to avoid issue:
223+
// ObjectDisposedException: Safe handle has been closed.
224+
connection1 = connection;
221225
connection.Close();
222226
connection.Dispose();
223227
}
@@ -231,6 +235,11 @@ ORDER BY b.width DESC
231235
// Delete temporary file
232236
try
233237
{
238+
// https://github.com/dotnet/efcore/issues/26580
239+
if (connection1 != null)
240+
{
241+
SqliteConnection.ClearPool(connection1);
242+
}
234243
File.Delete(tempDbPath);
235244
}
236245
catch (Exception ex)

Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ private void LoadFaviconsFromDb(string dbPath, List<Bookmark> bookmarks)
142142
return;
143143
}
144144

145+
// Cache connection for pool clean
146+
SqliteConnection connection1 = null;
147+
145148
try
146149
{
147150
// Since some bookmarks may have same favicon id, we need to record them to avoid duplicates
@@ -212,8 +215,9 @@ ORDER BY i.width DESC -- Select largest icon available
212215
}
213216
finally
214217
{
215-
// https://github.com/dotnet/efcore/issues/26580
216-
SqliteConnection.ClearPool(connection);
218+
// Cache connection and clear pool after all operations to avoid issue:
219+
// ObjectDisposedException: Safe handle has been closed.
220+
connection1 = connection;
217221
connection.Close();
218222
connection.Dispose();
219223
}
@@ -227,6 +231,11 @@ ORDER BY i.width DESC -- Select largest icon available
227231
// Delete temporary file
228232
try
229233
{
234+
// https://github.com/dotnet/efcore/issues/26580
235+
if (connection1 != null)
236+
{
237+
SqliteConnection.ClearPool(connection1);
238+
}
230239
File.Delete(tempDbPath);
231240
}
232241
catch (Exception ex)

0 commit comments

Comments
 (0)