fix(win): prevent crash when bthserv is disabled#87
Open
stoprocent wants to merge 1 commit into
Open
Conversation
When the Bluetooth Support Service (bthserv) is disabled, the adapter can still be enumerated while adapter.GetRadioAsync() resolves to a null radio. The central-role branch then called radio.StateChanged() on that null radio, crashing the entire process. OnRadioChanged() also runs as a fire_and_forget coroutine, so any escaping exception terminates the app rather than being handled. Guard the radio before wiring up StateChanged(), and broaden the coroutine's catch to catch(...) so any WinRT failure degrades to an empty adapter instead of taking down the process (mirrors the existing catch(...) handling in notify_map.cc / winrt_cpp.cc). Fixes #85 https://claude.ai/code/session_013BTp5XgwGPsnpgo8V1vdn7
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.
Problem
If the Windows Bluetooth Support Service (
bthserv) is disabled, the entire process crashes instead of degrading tounsupported/poweredOff.In
RadioWatcher::OnRadioChanged()the adapter can still be enumerated whileadapter.GetRadioAsync()resolves to a null radio. The central-role branch then unconditionally does:On top of that,
OnRadioChanged()is afire_and_forgetcoroutine, so any exception that escapes the singlecatch (const winrt::hresult_error&)(a different exception type, or a failure after aco_awaitresumes off-frame) terminates the whole process rather than being handled.Fix
Two small, defensive changes:
StateChanged()—if (adapter.IsCentralRoleSupported() && radio). With a null radio we fall through to the existing empty-adapter path instead of dereferencing it.catch (...)so any WinRT failure degrades to an empty adapter instead of crashing. This mirrors the existingcatch (...)handling already used innotify_map.ccandwinrt_cpp.cc.Note
The original report (#85) is a one-liner with no version/stack trace. This is the credible crash path given the code, and the hardening is worth doing regardless, but it would still be good to confirm noble version + OS build + the actual error with the reporter.
This touches the same function as #86 (the older-Windows-10 capability fix), so the two PRs will need a trivial conflict resolution depending on merge order.
Fixes #85
https://claude.ai/code/session_013BTp5XgwGPsnpgo8V1vdn7
Generated by Claude Code