Skip to content

fix(linux): dispatch dialog GTK calls via InvokeAsync to fix GTK3 segfault#5339

Merged
leaanthony merged 1 commit into
masterfrom
agent/engineer-linux/0ac021f2
May 5, 2026
Merged

fix(linux): dispatch dialog GTK calls via InvokeAsync to fix GTK3 segfault#5339
leaanthony merged 1 commit into
masterfrom
agent/engineer-linux/0ac021f2

Conversation

@leaanthony

@leaanthony leaanthony commented May 5, 2026

Copy link
Copy Markdown
Member

Closes #5338

Root cause

linuxDialog.show() launched runQuestionDialog() — which calls gtk_dialog_run() — from a bare goroutine. GTK3 is not thread-safe; all GTK/GDK calls must run on the GLib main thread. Running them from an arbitrary OS thread is undefined behaviour and causes segfaults.

Commit 5dc3e21 (GTK4 support, PR #4958) replaced the correct InvokeAsync call with a bare go func(), breaking GTK3 users.

Fix

Replace go func() { ... }() with InvokeAsync(func() { ... }) in linuxDialog.show(). This matches the pattern already used by showAboutDialog in the same file, which was unchanged and works correctly.

The inner go func() for user button callbacks is preserved — those are not GTK calls and are correct to run on a goroutine.

-	go func() {
+	InvokeAsync(func() {
 		response := runQuestionDialog(pointer(parent), m.dialog)
 		if response >= 0 && response < len(m.dialog.Buttons) {
 			button := m.dialog.Buttons[response]
 			if button.Callback != nil {
 				go func() {
 					defer handlePanic()
 					button.Callback()
 				}()
 			}
 		}
-	}()
+	})

Testing

  • Verified on Ubuntu 24.04 / GTK 3.24.41 / webkit2gtk 2.50.4
  • go test ./v3/pkg/application/ — all 170+ tests pass
  • Fixed binary (dialogs-basic example) builds cleanly with CGO_ENABLED=1

Summary by CodeRabbit

  • Refactor
    • Improved dialog-response handling execution on Linux for better reliability.

…fault

Commit 5dc3e21 (GTK4 support, #4958) replaced InvokeAsync with a bare
go func() in linuxDialog.show(). GTK3 requires all GTK calls to run on
the main thread; launching them from a goroutine causes a segfault.

Use InvokeAsync (same pattern as showAboutDialog) so runQuestionDialog
is dispatched to the GTK main thread on both GTK3 and GTK4. The button
callback is still invoked in a goroutine since it is not a GTK call.

Fixes #5338

Co-authored-by: multica-agent <github@multica.ai>
Copilot AI review requested due to automatic review settings May 5, 2026 14:58
@coderabbitai

coderabbitai Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8192e3ea-3959-4b92-ab3e-69a1111d7f09

📥 Commits

Reviewing files that changed from the base of the PR and between 6ad8205 and 2024bfa.

📒 Files selected for processing (1)
  • v3/pkg/application/dialogs_linux.go

Walkthrough

The change replaces a raw goroutine launch with InvokeAsync in the Linux dialog response handler to ensure dialog callbacks execute on the GTK thread, preventing segfaults under GTK3.

Changes

Linux Dialog Thread Safety

Layer / File(s) Summary
Core Logic
v3/pkg/application/dialogs_linux.go
Dialog response handling is routed through InvokeAsync(func() { ... }) instead of go func() to dispatch callbacks to the GTK main thread, fixing segfault crashes in GTK3.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • wailsapp/wails#4926: Both PRs replace off-GTK-thread goroutines with InvokeAsync-run closures in Linux dialog handling to maintain GTK thread safety.

Suggested labels

v3-alpha, Linux, size:S, bug-fix

Poem

🐰 A goroutine danced off the GTK beat,
Causing dialogs to crash, oh what a treat!
But InvokeAsync called them back home,
To the main thread they'd safely roam! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately summarizes the primary change: dispatching dialog GTK calls via InvokeAsync to fix GTK3 segfault.
Description check ✅ Passed Description covers root cause, fix explanation with code diff, and testing verification, but lacks checkbox selections from the template.
Linked Issues check ✅ Passed PR changes match issue #5338 requirements: replacing bare goroutine with InvokeAsync in linuxDialog.show() to fix GTK3 segfault, preserving inner goroutines for callbacks.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the GTK3 dialog segfault issue; no unrelated modifications present beyond the necessary InvokeAsync fix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/engineer-linux/0ac021f2

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.1)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@leaanthony leaanthony merged commit 533bbf3 into master May 5, 2026
60 of 61 checks passed
@leaanthony leaanthony deleted the agent/engineer-linux/0ac021f2 branch May 5, 2026 19:37
pull Bot pushed a commit to Mu-L/wails that referenced this pull request May 5, 2026
…ispatch dialog GTK calls via InvokeAsync to fix GTK3 segfault
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.

[v3] Dialogs are broken on Linux/GTK3

2 participants