GoogleChrome / samples

A repo containing samples tied to new functionality in each release of Google Chrome.
https://www.chromestatus.com/samples
Apache License 2.0
5.79k stars 2.38k forks source link

[web-bluetooth] Bluetooth device connection promise not resolving if device times out #668

Open olivierklaver opened 4 years ago

olivierklaver commented 4 years ago

There seems to be a bug in the web-bluetooth/automatic-reconnect example or in the way web bluetooth is implemented in Chrome. I have already filed a bug-report for Chrome, but since this may relate to API changes the bug may be caused by the fact that the sample code is out of date.

The problem: Bluetooth device connection promise not resolving if device times out.

Steps to reproduce the problem:

  1. Launch Chrome
  2. Go to: https://googlechrome.github.io/samples/web-bluetooth/automatic-reconnect.html
  3. Click Scan button
  4. Select BTLE device (Tested with Wahoo Cadence Sensor and Wahoo Heart Rate Sensor)
  5. Wait for the device to connect
  6. Let the sensor rest until it disconnects
  7. Wait for the 'gattserverdisconnected' event to be triggered and the first reconnect cycle to start
  8. The program will stall and the requestDevice() chooser will stop responding

What is the expected behavior? The bluetoothDevice.gatt.connect() call should time out after some time if the client can not connect to the server. This does happen if the client disconnects but not the server (The BT device).

What went wrong? The bluetoothDevice.gatt.connect() Promise seems to never get resolved. This does only happen if the device times out. If the device is removed via bluetoothDevice.gatt.disconnect() the API behaves as expected.

Chrome version: 79.0.3945.130 Channel: stable OS Version: OS X 10.15.2

PointerEvent commented 3 weeks ago

Sorry to bother you almost four years later, did you find a workaround for this issue? The issue does not seem to happen on my Windows machine but still seems to be a problem on Mac.

MacOS: 15.0.1 (24A348) Chrome: Version 130.0.6723.70 (Official Build) (arm64)

olivierklaver commented 3 weeks ago

Funny that you ask about this now, as I happened to revisit that part of the code yesterday and thought to myself, I wonder if this is still an issue in Chromium today! For me this issue only occurred with a specific heart-rate sensor that would sometimes disconnect after (and during) the initialization process. I ended up giving users the option to remove the sensor in the device manager of my app. But yea that is not a work-around just taking the L and moving on I guess. Could you tell me the sensor type, brand, and model you’re experiencing this issue with?

PointerEvent commented 3 weeks ago

This is actually happening with a Bosh laser rangefinder, Bosch PLR 50C. The steps to reproduce and the symptoms are quite similar to yours. Just that it seems to happen when the browser tab isn't active, such as leaving the tab out of focus for a while or locking the computer. When the script tries to reconnect it wont make it past the reconnection stage. No error is thrown and the device selection dialogue won't open after that without a refresh.

One theory is that the macs bluetooth api won't answer the chrome tab if it isn't active and chrome is left hanging, but that's just a hunch at the moment. Debugging is a bit slow since I'm not on a mac myself and I have to bother someone else every time I have something to try.