Repository navigation
Bound HCI requests by their timeout instead of 10 reads - #65
Merged
Merged
Conversation
sendRequest() ignored its timeout and gave up after reading 10 events. Its filter also passes LE meta events, so while the controller is scanning, advertising reports used up all 10 reads before the command's response arrived and the request failed with ETIMEDOUT. This made any HCI command unreliable during a scan, including the command that disables scanning. Wait for each event with poll() for the time remaining before the timeout, and keep reading until the matching response arrives or the timeout expires.
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.
sendRequest()ignored itstimeoutargument and gave up after reading 10 events. Its socket filter also passes LE meta events (needed for commands that complete with an LE subevent). So while the controller is scanning, advertising reports can use up all 10 reads before the command's response arrives, and the request fails withETIMEDOUTeven though the controller answered.This made any HCI command unreliable during a scan, including the LE Set Scan Enable that disables scanning. When that failed (the error is ignored in
lowEnergyScan), the controller kept scanning, and the next scan failed again.This change waits for each event with
poll()for the time remaining beforetimeout, and keeps reading until the matching response arrives or the timeout expires. A response that never arrives now also ends inETIMEDOUTinstead of blocking forever inread().Testing
Connection timed outbefore this change, and succeed after it. Debian 13, kernel 6.12, CSR 4.0 dongle, Swift 6.4.1.swift buildpasses.Related issues not fixed here
AsyncIndefiniteStream.stop()(Bluetooth) doesn't wait for the producer task. Its final scan-disable request can overlap the caller's next request on the same HCI socket, and both swap the socket filter.gatttoolis affected the same way.