Repository navigation
internal/kawa: tear the compositor down when Run returns - #25
Merged
Merged
Conversation
Run never destroyed Xwayland or the display, so every exit left the X lock and socket of its Xwayland and the Wayland socket behind. Run now tears everything down on every return, including Log Out, a canceled context, and a failure partway through setup. The order follows sway and tinywl. Xwayland goes first, because destroying its client along with the others makes wlroots restart it. Then come the other clients, the server's listeners and pipes, the textures, the cursor manager and cursor, the allocator, the renderer, the backend, and last the display.
DeedleFake
added this pull request to stack #26
October 2, 2026 21:56
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.
Why
Server.Runnever destroyed Xwayland or the Wayland display. Every exit, Log Out included, left/tmp/.X11-unix/XN,/tmp/.XN-lock, and thewayland-Nsocket and lock inXDG_RUNTIME_DIRbehind.wlr_xwayland_destroyandwl_display_destroyare what remove them. Run now defersteardownbeforeinit, so teardown runs on every return, including a failure partway through setup.Scope
teardownininternal/kawa/kawa.godestroys things in this order:DestroyClients. sway does the same.display.DestroyClients, thenreleasefor the remaining listeners and both pipes.wlr.Listener.Destroyhas a value receiver, soteardownzeroes the Xwayland listener field after it destroys the listener, andreleaseno longer destroys it.teardownchecksValid, or the zero value forwlr.Cursor, before it destroys an object that a failedinitmay not have created.Menu.Releasedestroys the textures of a menu's items.cleanup.shnow say that the X lock sweep only matters when kawa gets killed.Tradeoffs
A stack of cleanup functions pushed during
initwould not give the right order. Xwayland and the clients have to go first, and some textures come from later thaninit.Blast Radius
Every exit now runs wlroots destroy code that never ran before. A mistake there crashes kawa on its way out, after the session is over. SIGKILL still leaves the files behind.
Verification
go vet,go test,golangci-lint run --disable=errcheck, andgo fix -diffare clean, and each commit builds./tmp/.X0-lock,/tmp/.X11-unix/X0,wayland-0, andwayland-0.lockwere gone, and the next run got:0again. Before this change all four stayed after every exit.Listener.Destroy, so the check does catch that mistake.XDG_RUNTIME_DIR, Run fails after Xwayland starts. kawa exits with 1 and now leaves no X lock. WithWLR_BACKENDS=bogus,initfails, and kawa exits with 1 and no ASan report.