Skip to content

fix(win): prevent crash when bthserv is disabled#87

Open
stoprocent wants to merge 1 commit into
mainfrom
claude/fix-issue-85-bthserv-crash
Open

fix(win): prevent crash when bthserv is disabled#87
stoprocent wants to merge 1 commit into
mainfrom
claude/fix-issue-85-bthserv-crash

Conversation

@stoprocent

Copy link
Copy Markdown
Owner

Problem

If the Windows Bluetooth Support Service (bthserv) is disabled, the entire process crashes instead of degrading to unsupported / poweredOff.

In RadioWatcher::OnRadioChanged() the adapter can still be enumerated while adapter.GetRadioAsync() resolves to a null radio. The central-role branch then unconditionally does:

bluetooth = radio;                       // null
mRadioStateChangedRevoker = radio.StateChanged(...);   // call on null radio -> crash

On top of that, OnRadioChanged() is a fire_and_forget coroutine, so any exception that escapes the single catch (const winrt::hresult_error&) (a different exception type, or a failure after a co_await resumes off-frame) terminates the whole process rather than being handled.

Fix

Two small, defensive changes:

  1. Null-guard the radio before wiring up StateChanged()if (adapter.IsCentralRoleSupported() && radio). With a null radio we fall through to the existing empty-adapter path instead of dereferencing it.
  2. Broaden the coroutine catch to catch (...) so any WinRT failure degrades to an empty adapter instead of crashing. This mirrors the existing catch (...) handling already used in notify_map.cc and winrt_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

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

bthserv is disabled app is crash

2 participants