Repository navigation
fix: a cancelled or abandoned wait for a WiFi device no longer hangs forever - #146
Merged
Merged
Conversation
…forever DirectConnectInterface.waitForPeripheral()'s internal wait only ever settled on success: cancelling it (pauseBackgroundActivity, or a caller giving up) and its own 5-minute lifetime both just cleaned up internal state without resolving or rejecting the promise the caller was awaiting. Any caller awaiting that promise - directly or indirectly, such as BleAdapter.stop() awaiting a still in-flight start() via its underlying promise - was stuck for as long as the wait happened to keep running, in practice indefinitely whenever the device stayed unreachable. - waitForPeripheral()'s wait now rejects on cancel and on its own lifetime being reached, instead of only ever resolving. - a new cancelWait() lets a specific device's pending wait be settled without canceling every other interface's in-flight wait. - BleAdapter.start()'s task now calls cancelWait() via the existing onCancel hook when the start is stopped or times out, so a still-pending wait is interrupted immediately rather than left to its own, much longer, timeout. IBleInterface.cancelWait() is optional - an interface with no comparable internal wait doesn't need one. - runStop()'s wait on the previous start's underlying promise is now also bounded as a backstop, so stop() still returns even if some other promise in the chain genuinely never settles.
Checking a Promise-or-undefined field directly in a boolean conditional reads like an accidentally-skipped await. Made the intent (is it set at all, not whether it resolved truthy) explicit.
|
gdoumen
marked this pull request as ready for review
November 9, 2026 12:21
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
DirectConnectInterface.waitForPeripheral()'s internal wait only ever settled on success. Cancelling it (pauseBackgroundActivity, or a caller giving up) and its own 5-minute lifetime both cleaned up internal state without ever resolving or rejecting the promise the caller was awaiting.BleAdapter.stop()awaiting a still in-flightstart()via its underlying promise — could be stuck for as long as the wait kept running, in practice indefinitely whenever the device stayed unreachable.What changed
waitForPeripheral()'s wait now rejects on cancel and on reaching its own lifetime, instead of only ever resolving.cancelWait()to settle a specific device's pending wait without cancelling every other in-flight wait.BleAdapter.start()'s task now callscancelWait()via its existingonCancelhook when the start is stopped or times out, so a still-pending wait is interrupted immediately instead of left to its own, much longer, timeout.IBleInterface.cancelWait()is optional — an interface with no comparable internal wait doesn't need one.runStop()'s wait on the previous start's underlying promise is now also bounded as a backstop, sostop()still returns even if some other promise in the chain genuinely never settles.Test plan
direct-connect/base/interface.unit.test.ts,ble/fm/adapter.unit.test.ts), each manually verified to fail without its corresponding fix before being made to pass.tsc --noEmitclean.