Repository navigation
background_client: release the client reference under the mutex (fixes single-core shutdown crash) - #355
Merged
AlanGriffiths merged 2 commits intoOct 6, 2026
Conversation
BackgroundClient::stop() took a strong reference to Self before locking the mutex and released it after unlocking. On a single-core system the client thread woken by Self::stop() preempts the main thread right after the unlock, drops its own reference and returns from the runner lambda, which calls wl_display_disconnect(). The main thread then becomes the last owner and ~Self() destroys Wayland objects against a disconnected display: SIGSEGV in libwayland-client on every SIGTERM/SIGINT shutdown. Take the mutex first and let the strong reference die inside the locked scope. The client thread also takes the mutex before client.reset(), so it is always the last owner and destruction happens on the client thread before the display is disconnected. Fixes canonical#354 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
fast1ine
force-pushed
the
fix-background-client-stop-race
branch
from
October 6, 2026 13:05
c26fe98 to
a5a6696
Compare
AlanGriffiths
force-pushed
the
fix-background-client-stop-race
branch
from
October 6, 2026 14:13
2f045fd to
13f81c9
Compare
AlanGriffiths
enabled auto-merge
October 6, 2026 14:14
Contributor
|
@fast1ine the failing builds for arm64 and armhf are not your problem: they can't succeed in a PR from a fork. (Not sure why they were set up to run.) |
tarek-y-ismail
approved these changes
Oct 6, 2026
AlanGriffiths
disabled auto-merge
October 6, 2026 15:19
Contributor
|
@fast1ine the automation should publish the update on the |
saviq-work
pushed a commit
that referenced
this pull request
Oct 7, 2026
…s single-core shutdown crash) (#355) Fixes #354 `BackgroundClient::stop()` took a strong reference to `Self` before locking the mutex and released it after unlocking. On a single-core system the client thread woken by `Self::stop()` preempts the main thread right after the unlock, drops its own reference and returns from the runner lambda, which calls `wl_display_disconnect()`. The main thread then becomes the last owner and `~Self()` destroys Wayland objects against a disconnected display: SIGSEGV in libwayland-client (`wl_map`) on every SIGTERM/SIGINT shutdown. Taking the mutex first and letting the strong reference die inside the locked scope guarantees that the client thread, which also takes the mutex before `client.reset()`, is always the last owner, so destruction happens on the client thread before the display is disconnected. **Testing:** on an i.MX6 Solo (single Cortex-A9, armhf, Debian 13 host) every shutdown of the stock 24/stable and 24/candidate snaps crashes (exit 139). Forcing `SCHED_BATCH` on the frame threads, which removes the preemption described above, gives clean shutdowns every time, matching this analysis. I will re-test on the device with the edge build once this lands. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
saviq-work
pushed a commit
that referenced
this pull request
Oct 7, 2026
…s single-core shutdown crash) (#355) Fixes #354 `BackgroundClient::stop()` took a strong reference to `Self` before locking the mutex and released it after unlocking. On a single-core system the client thread woken by `Self::stop()` preempts the main thread right after the unlock, drops its own reference and returns from the runner lambda, which calls `wl_display_disconnect()`. The main thread then becomes the last owner and `~Self()` destroys Wayland objects against a disconnected display: SIGSEGV in libwayland-client (`wl_map`) on every SIGTERM/SIGINT shutdown. Taking the mutex first and letting the strong reference die inside the locked scope guarantees that the client thread, which also takes the mutex before `client.reset()`, is always the last owner, so destruction happens on the client thread before the display is disconnected. **Testing:** on an i.MX6 Solo (single Cortex-A9, armhf, Debian 13 host) every shutdown of the stock 24/stable and 24/candidate snaps crashes (exit 139). Forcing `SCHED_BATCH` on the frame threads, which removes the preemption described above, gives clean shutdowns every time, matching this analysis. I will re-test on the device with the edge build once this lands. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
saviq-work
pushed a commit
that referenced
this pull request
Oct 7, 2026
…s single-core shutdown crash) (#355) Fixes #354 `BackgroundClient::stop()` took a strong reference to `Self` before locking the mutex and released it after unlocking. On a single-core system the client thread woken by `Self::stop()` preempts the main thread right after the unlock, drops its own reference and returns from the runner lambda, which calls `wl_display_disconnect()`. The main thread then becomes the last owner and `~Self()` destroys Wayland objects against a disconnected display: SIGSEGV in libwayland-client (`wl_map`) on every SIGTERM/SIGINT shutdown. Taking the mutex first and letting the strong reference die inside the locked scope guarantees that the client thread, which also takes the mutex before `client.reset()`, is always the last owner, so destruction happens on the client thread before the display is disconnected. **Testing:** on an i.MX6 Solo (single Cortex-A9, armhf, Debian 13 host) every shutdown of the stock 24/stable and 24/candidate snaps crashes (exit 139). Forcing `SCHED_BATCH` on the frame threads, which removes the preemption described above, gives clean shutdowns every time, matching this analysis. I will re-test on the device with the edge build once this lands. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
saviq-work
pushed a commit
that referenced
this pull request
Oct 7, 2026
…s single-core shutdown crash) (#355) Fixes #354 `BackgroundClient::stop()` took a strong reference to `Self` before locking the mutex and released it after unlocking. On a single-core system the client thread woken by `Self::stop()` preempts the main thread right after the unlock, drops its own reference and returns from the runner lambda, which calls `wl_display_disconnect()`. The main thread then becomes the last owner and `~Self()` destroys Wayland objects against a disconnected display: SIGSEGV in libwayland-client (`wl_map`) on every SIGTERM/SIGINT shutdown. Taking the mutex first and letting the strong reference die inside the locked scope guarantees that the client thread, which also takes the mutex before `client.reset()`, is always the last owner, so destruction happens on the client thread before the display is disconnected. **Testing:** on an i.MX6 Solo (single Cortex-A9, armhf, Debian 13 host) every shutdown of the stock 24/stable and 24/candidate snaps crashes (exit 139). Forcing `SCHED_BATCH` on the frame threads, which removes the preemption described above, gives clean shutdowns every time, matching this analysis. I will re-test on the device with the edge build once this lands. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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 #354
BackgroundClient::stop()took a strong reference toSelfbefore locking the mutex and released it after unlocking. On a single-core system the client thread woken bySelf::stop()preempts the main thread right after the unlock, drops its own reference and returns from the runner lambda, which callswl_display_disconnect(). The main thread then becomes the last owner and~Self()destroys Wayland objects against a disconnected display: SIGSEGV in libwayland-client (wl_map) on every SIGTERM/SIGINT shutdown.Taking the mutex first and letting the strong reference die inside the locked scope guarantees that the client thread, which also takes the mutex before
client.reset(), is always the last owner, so destruction happens on the client thread before the display is disconnected.Testing: on an i.MX6 Solo (single Cortex-A9, armhf, Debian 13 host) every shutdown of the stock 24/stable and 24/candidate snaps crashes (exit 139). Forcing
SCHED_BATCHon the frame threads, which removes the preemption described above, gives clean shutdowns every time, matching this analysis. I will re-test on the device with the edge build once this lands.🤖 Generated with Claude Code