Skip to content

Linux: fix JVM abort at exit after a WebView was used (#64) - #65

Merged
shannah merged 1 commit into
masterfrom
claude/modest-lovelace-azu6z5
Oct 1, 2026
Merged

shannah merged 1 commit into
masterfrom
claude/modest-lovelace-azu6z5

Conversation

@shannah

@shannah shannah commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Fixes #64.

Root cause

WebKitGTK keeps the default WebKitWebContext in 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 its WebsiteDataStore are 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_handlers on the "VM Thread", g_object_unref is called on the default context. With a live view the refcount is 2, so nothing crashes. After dispose() 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 on webkit_web_context_get_default() on the pump thread, right after gtk_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-update and then /spdd-generate on 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 a data: page, confirms it loaded via evalAsync, disposes the component, then calls System.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:

  • Before the fix: exit status 134 (Aborted) in 2 of 2 runs
  • After the fix: exit status 0 in 3 of 3 runs
  • run-linux-media-smoketest.sh still passes

🤖 Generated with Claude Code

https://claude.ai/code/session_01CoHxtwpNJjWbAE5TMrB5Ld


Generated by Claude Code

…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
shannah marked this pull request as ready for review October 1, 2026 19:44
@shannah
shannah merged commit 2c0fc53 into master Oct 1, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux: JVM aborts at exit after a WebView was used

2 participants