Linux: fix JVM abort at exit after a WebView was used (#64) - #65
Merged
Merged
Conversation
…ts (#64) WebKitGTK releases its static reference to the default WebKitWebContext from libc exit handlers, which the JVM runs on its VM Thread. Once every view was disposed that was the last reference, so the context and its WebsiteDataStore were finalized off WebKit's main thread and a WebKit release assertion aborted the process (SIGABRT, exit status 134). The GTK pump now holds one never-released reference, taken on the pump thread right after gtk_init. Canvas 7 updated (Requirements, Approach, Structure, Safeguards) and the regression smoke test run-linux-exit-smoketest.sh / WebViewExitSmokeTest added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CoHxtwpNJjWbAE5TMrB5Ld
shannah
marked this pull request as ready for review
October 1, 2026 19:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #64.
Root cause
WebKitGTK keeps the default
WebKitWebContextin a function-local static reference. libc exit handlers release that reference, and the JVM runs them on its VM Thread (os::exit), not the GTK pump thread. Once every view has been disposed, that static holds the last reference. The context and itsWebsiteDataStoreare then finalized off WebKit's main thread, and WebKit's release assertion aborts the process. That matches the stack trace in the issue.I confirmed this under gdb: at
__run_exit_handlerson the "VM Thread",g_object_unrefis called on the default context. With a live view the refcount is 2, so nothing crashes. Afterdispose()the refcount is 1, so the context is finalized and the process aborts.Fix
GtkPump::ensure_started(src_c/webview_embed.cpp) takes one extra reference onwebkit_web_context_get_default()on the pump thread, right aftergtk_init, and never releases it. At exit the static release only decrements the count. The OS reclaims the context when the process ends.SPDD
This is a behavior change, so it went through
/spdd-prompt-updateand then/spdd-generateon Canvas 7 (Swing Lightweight WebView Embedding). That added a Requirements bullet (clean JVM exit), an Approach bullet (root cause and the deliberately leaked reference), a Structure entry, and a Safeguard ("the default context is never finalized").Test
New regression smoke test
run-linux-exit-smoketest.sh→demos/WebViewExitSmokeTest. It creates a LIGHTWEIGHT component, loads adata:page, confirms it loaded viaevalAsync, disposes the component, then callsSystem.exit(0). The script's exit status is the JVM's.Results on Ubuntu 24.04, WebKitGTK 2.52.6, OpenJDK 21, under
xvfb-run:Aborted) in 2 of 2 runsrun-linux-media-smoketest.shstill passes🤖 Generated with Claude Code
https://claude.ai/code/session_01CoHxtwpNJjWbAE5TMrB5Ld
Generated by Claude Code