fix(v3/linux): release WebKitURISchemeRequest on the GTK main context#5566
Conversation
request.Close() runs on the assetserver goroutine and dropped what may be the last reference to the WebKitURISchemeRequest there. Finalizing a WebKit GObject off the GTK main thread violates WebKitGTK's threading rules and intermittently crashes long-running apps with a SIGSEGV in g_object_unref during cgo execution. Schedule the unref onto the default GMainContext with g_main_context_invoke instead, in both the GTK3 (webkit2gtk-4.1) and GTK4 (webkitgtk-6.0) request implementations, which share the pattern. g_object_ref in NewRequest is unchanged: ref/unref themselves are atomic; only the finalization triggered by the final unref is main-thread-only. Verified: gtk3 and gtk4 builds plus assetserver/application test suites pass on Linux (Ubuntu, WebKitGTK 4.1/6.0). The equivalent workaround was validated in production by the reporter over multi-day runs. Fixes #5557
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughC helper functions were added to Linux WebKit request handlers to schedule ChangesGTK main context marshalling for WebKit request finalization
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" 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. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes an intermittent Linux crash in the v3 assetserver WebView request cleanup path by ensuring WebKitURISchemeRequest is unref’d on the GTK main context (avoiding off-main-thread finalization of a WebKit GObject), and documents the fix in the unreleased changelog.
Changes:
- Marshal
WebKitURISchemeRequestfinalg_object_unrefonto the defaultGMainContextviag_main_context_invokefor GTK4 (webkitgtk-6.0) builds. - Apply the same main-context unref scheduling for GTK3 (
webkit2gtk-4.1) builds. - Add an unreleased changelog entry describing the crash fix and linking to #5557.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| v3/internal/assetserver/webview/request_linux.go | Dispatches request unref onto the GTK main context for GTK4 builds to prevent off-thread finalization. |
| v3/internal/assetserver/webview/request_linux_gtk3.go | Mirrors the same main-context unref scheduling for GTK3 builds. |
| v3/UNRELEASED_CHANGELOG.md | Records the Linux SIGSEGV fix and references #5557. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Description
request.Close()runs on the assetserver goroutine (AssetServer.processWebViewRequest→webViewAssetRequest.Close) and dropped what may be the last reference to theWebKitURISchemeRequestthere. Finalizing a WebKit GObject off the GTK main thread violates WebKitGTK's threading rules and intermittently kills long-running apps with:Fix
Schedule the unref onto the default
GMainContextwithg_main_context_invokeinstead of unreffing inline. Applied to both the GTK3 (webkit2gtk-4.1) and GTK4 (webkitgtk-6.0) request implementations, which share the identical pattern.g_object_refinNewRequestis intentionally unchanged: GObject ref/unref are atomic and thread-safe in themselves — only the finalization triggered by dropping the final reference is main-thread-only.g_main_context_invokeruns the callback immediately if the caller already owns the main context, so this is also correct if Close ever runs on the UI thread.Verification
go build/go vetwith-tags gtk3and default gtk4 tags pass on Linux (Ubuntu, WebKitGTK 4.1 + 6.0).go testfor./internal/assetserver/...and./pkg/application(under xvfb, gtk3 tags) passes.WebKitURISchemeRequestunder load. The equivalent patch (unref viag_main_context_invoke) was validated by the reporter in production over multi-day runs (see [v3][Linux][GTK3] Intermittent SIGSEGV in assetserver when closing WebKitURISchemeRequest (g_object_unref) #5557).Fixes #5557
Type of change
Checklist:
v3/UNRELEASED_CHANGELOG.mdSummary by CodeRabbit