fix(win): maintain the GATT session to stabilize MTU negotiation#88
Open
stoprocent wants to merge 1 commit into
Open
fix(win): maintain the GATT session to stabilize MTU negotiation#88stoprocent wants to merge 1 commit into
stoprocent wants to merge 1 commit into
Conversation
Set GattSession.MaintainConnection(true) after creating the session so Windows establishes the physical BLE connection up front. On Windows, BluetoothLEDevice::FromBluetoothAddressAsync returns before the link is established. Without MaintainConnection the first GATT operation (GetGattServicesAsync) triggers the connection, but by then the MTU is still at the default 23. If the peripheral negotiates a larger MTU during service discovery, the race can exhaust the peripheral's ATT buffer pool. MaintainConnection defaults to false and the session is released in PeripheralWinrt::Disconnect(), so the link is not kept open after an intentional disconnect. This carries the same change as #82 by @ranbochen, re-applied on a branch in this repository so CI can run on it. Co-authored-by: ranbochen <5681057+ranbochen@users.noreply.github.com> 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.
Summary
Sets
GattSession.MaintainConnection(true)right after the session is created inOnGattSessionCreated, so Windows establishes the physical BLE connection up front instead of lazily on the first GATT operation.On Windows,
BluetoothLEDevice::FromBluetoothAddressAsyncreturns before the link is established. WithoutMaintainConnection, the first GATT operation (GetGattServicesAsync) triggers the connection — but by then the MTU is still the default 23. If the peripheral negotiates a larger MTU during service discovery, the race can exhaust the peripheral's ATT buffer pool.MaintainConnectiondefaults tofalse, and the session is released inPeripheralWinrt::Disconnect()(gattSession->Close()), so this does not keep the link open after an intentional disconnect.Verified against Microsoft's documentation
GattSession.MaintainConnection— read/writeBoolean, defaultfalse; whentrue"the system waits indefinitely for a connection, and it will connect when the device is available."GattSession.MaintainConnectionto true, or call an uncached service discovery method … or perform a read/write operation." This confirms the lazy-connect behavior the change addresses.Why this PR exists
This is the same change as #82 by @ranbochen — full credit to them (preserved as co-author on the commit). That PR is a first-time-contributor fork PR, and for some reason its CI never ran: the workflow runs queued at open time were gated for approval and have since aged out, leaving 0 checks and no way to re-trigger them from that PR. Re-applying the change on a branch in this repository lets the build/test/lint workflows run normally and go through the standard review gates.
Supersedes #82.
🤖 Generated with Claude Code
https://claude.ai/code/session_013BTp5XgwGPsnpgo8V1vdn7
Generated by Claude Code