Repository navigation
internal/kawa: stop Run when its context is canceled - #24
Merged
Merged
Conversation
wl_display_terminate is not safe to call from another goroutine, so a context.AfterFunc writes to a pipe that the event loop watches, and the loop terminates the display itself. Run returns nil in that case. Run also locks its goroutine to one OS thread. wlroots keeps per-thread state between calls, such as the EGL context that a GLES2 render pass holds current from begin to submit.
The first SIGINT or SIGTERM cancels the context given to Run. A second one gets the default behavior, so it still kills kawa if shutting down gets stuck.
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.Runtook a context but ignored it, andcmd/kawahad no signal handling, so SIGTERM killed kawa outright with status 143. Run now returns nil when its context is canceled, andcmd/kawacancels that context on SIGINT or SIGTERM.wl_display_terminateis not safe to call from another goroutine. It sets a plain bool, andwl_display_runresets that bool when it starts, so an early call is lost. Instead, acontext.AfterFuncwrites a byte to a pipe that the event loop watches withEventLoop.AddFd. The loop reads the byte and terminates the display itself. A cancel that comes before the loop starts waits in the pipe until it does.Scope
loopPipeininternal/kawa/pipe.goholds the pipe and event source thatexitedused to set up inline.exitedand the newcanceledpipe both use it.newLoopPipealso closes the pipe if a later setup step fails, and checks thatAddFdsucceeded.releasecloses the pipe,Runstops theAfterFunc, or waits for its write if it has already started. That happens on every return, Log Out included.Runcallsruntime.LockOSThread. wlroots keeps per-thread state between calls. A GLES2 render pass makes its EGL context current in begin and releases it in submit, and the GL calls between them are separate cgo calls. Today every render pass runs inside a frame callback, which already pins the goroutine, so nothing visible changes. The lock keeps the setup calls before the loop on the loop's thread too.cmd/kawausessignal.NotifyContextforos.Interruptandsyscall.SIGTERM. After the first signal it calls the returnedstop, so a second signal still kills kawa if shutdown hangs.Runstill does not destroy Xwayland or the display after the loop exits, so the X lock, the X socket, and the Wayland socket stay behind as before.Blast Radius
SIGINT and SIGTERM now go through the normal return from
Run, so kawa exits with status 0 instead of dying from the signal. Log Out behaves as before. Theexitedpipe behind New moved intoloopPipeand keeps its behavior.Verification
go vet,go test,golangci-lint run --disable=errcheck, andgo fix -diffare clean, and each commit builds. A-racebuild stopped with SIGTERM reports no races.failed to read Wayland events: Broken pipeline as master. Master exits with 143 on SIGTERM.initruns and before the loop starts, still exits with 0. Sent within 3 ms, beforemaininstalls its handler, it kills kawa with 143.