Skip to content

BrowserBookmark do not use SqliteConnection pooling to avoid ObjectDisposedException #3674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2025

Conversation

Jack251970
Copy link
Member

@Jack251970 Jack251970 commented Jun 7, 2025

Do not use pooling so that we do not need to clear pool to avoid ObjectDisposedException.

Follow on with #3641.

Issue:

EXCEPTION OCCURS: System.ObjectDisposedException: Safe handle has been closed.
Object name: 'SafeHandle'.
   at IntPtr System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, ref bool success)
   at int SQLitePCL.SQLite3Provider_e_sqlite3+NativeMethods.sqlite3_prepare_v2(sqlite3 db, Byte* pSql, int nBytes, out IntPtr stmt, out Byte* ptrRemain)
   at int SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_prepare_v2(sqlite3 db, ReadOnlySpan<byte> sql, out IntPtr stm, out ReadOnlySpan<byte> tail)
   at IEnumerable<(sqlite3_stmt Statement, int ParamCount)> Microsoft.Data.Sqlite.SqliteCommand.PrepareAndEnumerateStatements()+MoveNext()
   at IEnumerable<sqlite3_stmt> Microsoft.Data.Sqlite.SqliteCommand.GetStatements()+MoveNext()
   at bool Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
   at SqliteDataReader Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
   at void Flow.Launcher.Plugin.BrowserBookmark.ChromiumBookmarkLoader.LoadFaviconsFromDb(string dbPath, List<Bookmark> bookmarks)+(Bookmark bookmark) => { } in C:/projects/flow-launcher/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs:line 224

@Jack251970 Jack251970 requested a review from Copilot June 7, 2025 16:16
@Jack251970 Jack251970 self-assigned this Jun 7, 2025
@Jack251970 Jack251970 added the Dev branch only An issue or fix for the Dev branch build label Jun 7, 2025
@Jack251970 Jack251970 added this to the 1.20.1 milestone Jun 7, 2025
@Jack251970 Jack251970 enabled auto-merge June 7, 2025 16:16
Copy link

gitstream-cm bot commented Jun 7, 2025

🥷 Code experts: onesounds, Yusyuriv

Jack251970, onesounds have most 👩‍💻 activity in the files.
Jack251970, onesounds have most 🧠 knowledge in the files.

See details

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

Activity based on git-commit:

Jack251970 onesounds
JUN 47 additions & 25 deletions
MAY 11 additions & 1 deletions
APR 81 additions & 92 deletions
MAR 17 additions & 7 deletions 183 additions & 18 deletions
FEB
JAN

Knowledge based on git-blame:
Jack251970: 42%
onesounds: 21%

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

Activity based on git-commit:

Jack251970 onesounds
JUN 240 additions & 123 deletions
MAY
APR 55 additions & 60 deletions
MAR 32 additions & 12 deletions 407 additions & 261 deletions
FEB
JAN

Knowledge based on git-blame:
Jack251970: 59%
onesounds: 24%

To learn more about /:\ gitStream - Visit our Docs

This comment has been minimized.

Copy link

gitstream-cm bot commented Jun 7, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

1 similar comment
Copy link

gitstream-cm bot commented Jun 7, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses ObjectDisposedException errors by caching the SqliteConnection instance and deferring SqliteConnection.ClearPool until after all operations, including file deletion.

  • Introduces a connection1 variable to hold the connection reference for pool clearing
  • Assigns the connection to connection1 in the existing finally block before disposing
  • Adds a second try block to call ClearPool(connection1) after deleting the temporary DB

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs Cache and defer clearing the SQLite connection pool to prevent disposed-handle errors
Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs Mirror changes from Firefox loader: cache connection and clear pool post-operations
Comments suppressed due to low confidence (1)

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

  • [nitpick] The variable name connection1 is not descriptive. Consider renaming it to something like cachedConnection to clarify its purpose.
SqliteConnection connection1 = null;

Copy link
Contributor

coderabbitai bot commented Jun 7, 2025

📝 Walkthrough

Walkthrough

The changes refactor favicon loading in Chromium and Firefox bookmark plugins by delegating database copying, error handling, and temporary file management to a new FaviconHelper class. SQLite connection pooling is disabled (Pooling=false) to avoid clearing pools and related exceptions. Favicon saving and SVG detection are also moved to helper methods.

Changes

File(s) Change Summary
Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs, Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs Refactored LoadFaviconsFromDb to delegate temp DB handling and error management to FaviconHelper.LoadFaviconsFromDb; disabled SQLite pooling; removed pool clearing calls; replaced favicon saving and SVG checks with helper methods.
Plugins/Flow.Launcher.Plugin.BrowserBookmark/Helper/FaviconHelper.cs Added new static helper class with methods for loading favicons from DB with temp file management, saving bitmap data, and detecting SVG data.

Suggested labels

bug

Suggested reviewers

  • jjw24
  • taooceros

Poem

🐇 A hop, a skip, a little tweak,
Connections closed, no errors sneak.
Pooling off, the code runs free,
Bookmarks load with harmony.
A bunny’s fix, both swift and bright,
Making data flow just right! ✨📚

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs (1)

158-159: Consider using a more descriptive variable name.

The caching approach is correct for deferring pool clearing, but connection1 could be more descriptive.

Consider renaming to something more explicit:

-        // Cache connection for pool clean
-        SqliteConnection connection1 = null;
+        // Cache connection for pool clearing after parallel operations
+        SqliteConnection poolClearConnection = null;
Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs (1)

145-146: Consistent implementation with ChromiumBookmarkLoader.

Good consistency between the two loaders. Same suggestion applies here for a more descriptive variable name.

Consider using the same naming improvement:

-        // Cache connection for pool clean
-        SqliteConnection connection1 = null;
+        // Cache connection for pool clearing after parallel operations
+        SqliteConnection poolClearConnection = null;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a4b4de and c8e82cb.

📒 Files selected for processing (2)
  • Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs (3 hunks)
  • Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (4)
Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs (2)

222-224: Excellent fix for the ObjectDisposedException issue.

The approach of caching a connection reference instead of calling ClearPool immediately in each thread's finally block correctly addresses the race condition. The race condition on the assignment itself is harmless since any connection reference will work for clearing the pool.


238-242: Correct implementation of deferred pool clearing.

The null check and single pool clearing call after all parallel operations complete is the right approach. This ensures all connections are properly closed before clearing the pool, preventing the ObjectDisposedException.

Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs (2)

218-220: Correct and consistent fix implementation.

The connection caching approach is identical to ChromiumBookmarkLoader and correctly addresses the ObjectDisposedException. Good consistency between the two bookmark loaders.


234-238: Properly implemented deferred pool clearing.

The implementation correctly mirrors the ChromiumBookmarkLoader fix. The null check and single pool clearing call after parallel operations complete resolves the ObjectDisposedException while maintaining proper resource management.

@Jack251970 Jack251970 changed the title Cache connection and clear pool after all operations to avoid ObjectDisposedException Do not use pooling so that we do not need to clear pool to avoid ObjectDisposedException Jun 8, 2025

This comment has been minimized.

Copy link

github-actions bot commented Jun 8, 2025

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors and Warnings Count
❌ forbidden-pattern 22
⚠️ non-alpha-in-dictionary 13

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
Plugins/Flow.Launcher.Plugin.BrowserBookmark/Helper/FaviconHelper.cs (1)

68-75: Consider enhancing SVG detection robustness.

The current implementation checks for basic SVG patterns but could be more comprehensive. Consider adding checks for common SVG namespace declarations or MIME type headers.

 public static bool IsSvgData(byte[] data)
 {
     if (data.Length < 5)
         return false;
     string start = System.Text.Encoding.ASCII.GetString(data, 0, Math.Min(100, data.Length));
-    return start.Contains("<svg") ||
-           (start.StartsWith("<?xml") && start.Contains("<svg"));
+    return start.Contains("<svg") ||
+           start.Contains("xmlns=\"http://www.w3.org/2000/svg\"") ||
+           (start.StartsWith("<?xml") && start.Contains("<svg"));
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ed32b3 and d7b8f85.

📒 Files selected for processing (3)
  • Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs (6 hunks)
  • Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs (6 hunks)
  • Plugins/Flow.Launcher.Plugin.BrowserBookmark/Helper/FaviconHelper.cs (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check Spelling
Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs

[warning] 28-28: moz is not a recognized word. (unrecognized-spelling)


[warning] 29-29: moz is not a recognized word. (unrecognized-spelling)


[warning] 30-30: moz is not a recognized word. (unrecognized-spelling)


[warning] 31-31: moz is not a recognized word. (unrecognized-spelling)


[warning] 252-252: newblahprofile is not a recognized word. (unrecognized-spelling)


[warning] 279-279: absolue is not a recognized word. (unrecognized-spelling)


[warning] 279-279: absolue is not a recognized word. (unrecognized-spelling)


[warning] 285-285: absolue is not a recognized word. (unrecognized-spelling)

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

[warning] 56-56: Favicons is not a recognized word. (unrecognized-spelling)


[warning] 58-58: Favicons is not a recognized word. (unrecognized-spelling)


[warning] 61-61: favicons is not a recognized word. (unrecognized-spelling)


[warning] 63-63: Favicons is not a recognized word. (unrecognized-spelling)


[warning] 133-133: Favicons is not a recognized word. (unrecognized-spelling)


[warning] 140-140: favicons is not a recognized word. (unrecognized-spelling)


[warning] 162-162: favicons is not a recognized word. (unrecognized-spelling)


[warning] 183-183: favicons is not a recognized word. (unrecognized-spelling)

🪛 GitHub Check: Check Spelling
Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs

[warning] 162-162:
favicons is not a recognized word. (unrecognized-spelling)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (9)
Plugins/Flow.Launcher.Plugin.BrowserBookmark/FirefoxBookmarkLoader.cs (4)

7-7: Good addition of the helper namespace.

This import enables the use of the new FaviconHelper class for centralized favicon operations.


122-199: Excellent refactoring that addresses the ObjectDisposedException issue.

The delegation to FaviconHelper.LoadFaviconsFromDb properly centralizes database copying, error handling, and cleanup operations. The use of Pooling=false in the SQLite connection string (line 132) effectively prevents the ObjectDisposedException by eliminating the need for connection pool clearing.

Key improvements:

  • Eliminates duplicate code between Firefox and Chromium loaders
  • Centralizes error handling and temporary file management
  • Removes problematic SqliteConnection.ClearPool calls
  • Maintains the same favicon extraction logic within the lambda

170-170: Good use of centralized SVG detection.

The FaviconHelper.IsSvgData method provides a reusable way to detect SVG image data, improving code maintainability.


182-182: Proper delegation of bitmap saving to helper method.

Using FaviconHelper.SaveBitmapData ensures consistent error handling and logging across all bookmark loaders.

Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs (3)

7-7: Consistent namespace import.

Matches the Firefox loader implementation for using the new FaviconHelper class.


135-203: Consistent refactoring that mirrors the Firefox loader approach.

The delegation to FaviconHelper.LoadFaviconsFromDb follows the same pattern as the Firefox loader, ensuring consistency across browser implementations. The Pooling=false setting (line 145) properly addresses the ObjectDisposedException issue by avoiding connection pool management altogether.

The refactoring successfully:

  • Eliminates code duplication with the Firefox loader
  • Centralizes database file handling and error management
  • Maintains the original Chromium-specific favicon extraction logic
  • Removes problematic pool clearing operations
🧰 Tools
🪛 GitHub Check: Check Spelling

[warning] 183-183:
favicons is not a recognized word. (unrecognized-spelling)


[warning] 162-162:
favicons is not a recognized word. (unrecognized-spelling)


[warning] 140-140:
favicons is not a recognized word. (unrecognized-spelling)

🪛 GitHub Actions: Check Spelling

[warning] 140-140: favicons is not a recognized word. (unrecognized-spelling)


[warning] 162-162: favicons is not a recognized word. (unrecognized-spelling)


[warning] 183-183: favicons is not a recognized word. (unrecognized-spelling)


161-167: SQL query formatting improvement.

The multi-line formatting enhances readability while preserving the original query logic.

🧰 Tools
🪛 GitHub Check: Check Spelling

[warning] 162-162:
favicons is not a recognized word. (unrecognized-spelling)

🪛 GitHub Actions: Check Spelling

[warning] 162-162: favicons is not a recognized word. (unrecognized-spelling)

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Helper/FaviconHelper.cs (2)

10-54: Well-designed method for database operations with comprehensive error handling.

The LoadFaviconsFromDb method effectively centralizes the complex logic of copying favicon databases, executing operations on temporary copies, and ensuring proper cleanup. The nested try-catch structure (lines 21-34) appropriately handles cleanup failures without masking the original copying error.

Key strengths:

  • Proper temporary file management with unique GUID naming
  • Comprehensive error logging for all failure scenarios
  • Guaranteed cleanup even when the primary operation fails
  • Clean separation of concerns through the action delegate pattern

56-66: Simple and robust bitmap saving implementation.

The method provides a clean interface for saving image data with appropriate error handling and logging.

@Jack251970 Jack251970 requested a review from jjw24 June 13, 2025 12:34
@jjw24 jjw24 changed the title Do not use pooling so that we do not need to clear pool to avoid ObjectDisposedException BrowserBookmarks do not use SqliteConnection pooling Jun 13, 2025
@jjw24 jjw24 changed the title BrowserBookmarks do not use SqliteConnection pooling BrowserBookmark do not use SqliteConnection pooling Jun 13, 2025
@jjw24 jjw24 changed the title BrowserBookmark do not use SqliteConnection pooling BrowserBookmark do not use SqliteConnection pooling to avoid ObjectDisposedException Jun 13, 2025
@Jack251970 Jack251970 merged commit 1415df2 into dev Jun 13, 2025
19 of 20 checks passed
@Jack251970 Jack251970 deleted the clear_pool branch June 13, 2025 13:13
jjw24 pushed a commit that referenced this pull request Jun 13, 2025
Cache connection and clear pool after all operations to avoid ObjectDisposedException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dev branch only An issue or fix for the Dev branch build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants