Skip to content

GATT operation in progress - how to handle it? #188

Open

Description

@perja12

I have a web page that writes to a characteristic, but if I do this too fast, I will get the error "GATT operation in progress". Is this something the page author should handle or should the implementation take care of queuing the requests?

If it is the page author, it will be good to include some recommendations for how to handle this. AFAIK there is no way to query the state of the implementation other than responding to the errors.

Activity

  1. beaufortfrancois commented on Nov 24, 2015

    @beaufortfrancois
    Collaborator

    Are you testing this on Chrome OS or Android?

  2. perja12 commented on Nov 24, 2015

    @perja12
    Author

    Testing this on Android (Chrome Dev build) and soon in Opera internal build.

  3. beaufortfrancois commented on Nov 24, 2015

    @beaufortfrancois
    Collaborator

    I believe this issue has been fixed recently (https://codereview.chromium.org/1465863003/).
    You may want to try with the latest Chromium build at https://download-chromium.appspot.com/?platform=Android and let me know if you're still experiencing this.

  4. perja12 commented on Nov 24, 2015

    @perja12
    Author

    Tested the latest Chromium and the crash when "GATT operation in progress" occurs has been fixed - so that is good.

    But my main question is still open: is it the responsibility of the page author to handle "GATT operation in progress" or should this be handled by the implementation? There seems to be pros and cons with both approaches.

  5. beaufortfrancois commented on Nov 24, 2015

    @beaufortfrancois
    Collaborator

    Glad to hear that.

    Hopefully @g-ortuno @scheib or @jyasskin will be able to fully answer your question here.

  6. jyasskin commented on Nov 24, 2015

    @jyasskin
    Member

    The implementation's supposed to handle it, but we don't yet (https://crbug.com/560862). @scheib has argued that we should make the web page handle it instead, in which case the rule would be that you wait for the writeValue() Promise to settle before calling writeValue() again. If there's a good reason you can't do that, it would probably settle the argument.

  7. scheib commented on Nov 24, 2015

    @scheib
    Contributor

    We should keep the implementation flexible, and not force queuing if the application doesn't desire it.

    12:35 AM Hi, short question about web-bluetooth: I have a page that writes to a characteristic whenever a button is pressed (or actually a touch event), but if I click to fast I get the "GATT operation in progress"-error. Is it so that the page author is supposed to handle this with a queue or similar, or will the implementation do the queing?
    1:12 AM perja: Currently unspecified. We should pick and make it clear. Some devices may be fairly slow to accept a write. What should happen if the web page can generate write requests at 2 times the speed a device can process them? If the browser queues, should it pick any limit for how large the queue should get? An application can know if a queue of unlimited values is needed or if only 1 pending value needs to be queued and replaced if a newer value arrives.

  8. pzboyz commented on Nov 26, 2015

    @pzboyz

    Truly low power devices will be setting connection intervals of +100ms, and it is highly likely that only one GATT operation may be handled per connection interval, arguably the page author does not need to know the GATT operations have entered a queue, but it will need to know which ones have been executed. Imagine a case where the web page has written to a characteristic expecting the device behaviour to change, if that operation is 4th in the queue, the device may still send notification indicating it is still performing with the previous old behaviour, what is the web page to do given that it thinks the GATT operations have already been sent?

  9. jyasskin commented on Nov 26, 2015

    @jyasskin
    Member

    When the web page wants to know which writes have completed, it needs to attach a handler to the Promise returned by writeValue(). If the implementation doesn't queue, every use of writeValue needs to be handled like this, while if we do queue, sites that don't care about latency (e.g. sites that only write in response to a user gesture, and for which the device itself gives feedback that the operation is finished) can write simpler code.

  10. g-ortuno commented on Nov 30, 2015

    @g-ortuno
    Contributor

    I think we should keep the implementation as simple as possible for now. Writing a library/polyfill to queue GATT operations is fairly trivial and would allow us to iterate faster if unforeseen problems arise.

  11. LeonNicholls commented on Dec 7, 2015

    @LeonNicholls

    Agree with @scheib about keeping the implementation flexible. It is easy enough to wait for fast write operations and not all apps need to have queuing.

  12. jyasskin commented on Dec 7, 2015

    @jyasskin
    Member

    SG. In order to write the queuing library, we'd need to guarantee that two separate tabs using Bluetooth concurrently, or a tab and an extension/app, or a tab and the OS, couldn't cause the tab to see an in progress error. Is that something the implementation can guarantee with simpler code than just queuing everything?

  13. g-ortuno commented on Dec 7, 2015

    @g-ortuno
    Contributor

    We don't get any signals from the system that the there is an operation in progress. Which also means our implementation of queuing couldn't guarantee no in progress errors since a Tab could get an in progress error if another App is using bluetooth.

  14. 8 remaining items

  15. beaufortfrancois commented on Oct 20, 2016

    @beaufortfrancois
    Collaborator

    For the record, here are not supported parallel operations and their respective errors I've found on current Dev Channel (55.0.2883.17):

    Android

    • readValue - DOMException: GATT operation failed for unknown reason.
    • writeValue - DOMException: GATT operation already in progress.

    Chrome OS / Linux

    • gatt.connect - DOMException: Connection failed for unknown reason.
    • readValue - DOMException: GATT Error Unknown.
    • writeValue - DOMException: GATT operation already in progress.

    Mac OS

    • readValue - DOMException: GATT Error: Not supported.
    • writeValue - DOMException: GATT operation already in progress.
    • stopNotifications is not implemented yet.

    As you can see, parallel connects works fine on Android and Mac OS while they're not on Chrome OS and Linux (BlueZ).
    readValue error message is not consistent across platforms.
    stopNotifications is not implemented yet on Mac OS but I suspect it should work fine eventually.

  16. jyasskin commented on Oct 20, 2016

    @jyasskin
    Member

    I'm planning to add a statement that UAs MAY return a NetworkError for concurrent use of connect, readValue, and writeValue. I hope we can remove that again in the future, but I want the spec to reflect reality until the implementations are improved.

  17. jyasskin commented on Oct 20, 2016

    @jyasskin
    Member

    #316 includes startNotifications() too, because I can't believe that writing characteristics needs serialization, but writing the CCC descriptor doesn't.

  18. g-ortuno commented on Oct 20, 2016

    @g-ortuno
    Contributor

    I think they are somewhat different. When you call writeValue() multiple times you expect each write to be sent to the device whereas when you call startNotifications() multiple times you don't expect each call to write to the descriptor so we can queue on the first write to the descriptor succeeding or failing.

  19. jyasskin commented on Oct 20, 2016

    @jyasskin
    Member

    If you're writing one characteristic, and you concurrently start notifications on another one, does that work?

  20. beaufortfrancois commented on Oct 21, 2016

    @beaufortfrancois
    Collaborator

    FYI, with BlueZ, I get the error below:

    characteristic.readValue().catch(err => console.log('readValue', err));
    characteristic2.startNotifications().catch(err => console.log('startNotifications', err));
    readValue DOMException: GATT operation failed for unknown reason.
    
  21. WayneKeenan commented on Dec 23, 2017

    @WayneKeenan

    I'm using the Nordic UART service with a tweak that inconsistently triggers Uncaught (in promise) DOMException: GATT operation already in progress.

    The tweak is that during the UART writeCharacteristic my BLE service handler on the peripheral is sending a notification (on the other notification-only characteristic) before the service handler returns.

    Sometimes it works, once or twice, sometimes the JS notification event isnt called and sometimes it errors with the above message sporadical and then sometimes continuously.

    Works fine using LightBlue.

    I'm on MacOS 10.12 and Chrome Version 63.0.3239.84 (Official Build) (64-bit)

  22. LiXi12 commented on Aug 20, 2020

    @LiXi12

    Write demo for the first time
    In server.getPrimaryService The whole thing stopped
    There was no reaction
    I guarantee that he has this UUID
    Think I filtered it in the filter

  23. scheib commented on Aug 20, 2020

    @scheib
    Contributor

    @woshiyigelaji I recommend asking on stackoverflow.com/questions/tagged/web-bluetooth and including more information so that people can help you diagnose the issue. https://www.chromium.org/developers/how-tos/file-web-bluetooth-bugs has tips on how to get logs about what is happening.

  24. nico-martin commented on Sep 28, 2021

    @nico-martin

    I have several characteristics that all read out their values at the same time (when the webapp is started). Unfortunately, this causes a "DOMException: GATT operation failed for unknown reason" error. I assume this happens because the connection is busy.

    Since there are different characteristics that perform different operations in different parts of the app, I can't really put it in a global promise queue. Are there any ideas if and how these conflicts could be solved internally?

  25. scheib commented on Sep 28, 2021

    @scheib
    Contributor

    For the foreseeable future I believe the answer is to write web-app utility code/library that will queue the requests. Recent work on Web Bluetooth has been focused on implementing the current spec and solving implementation and reliability errors.

  26. beaufortfrancois commented on Sep 29, 2021

    @beaufortfrancois
    Collaborator

    For the record, we're discussing with as well at https://twitter.com/nic_o_martin/status/1443108799737483268

  27. sepp89117 commented on Dec 14, 2022

    @sepp89117

    Hi,
    I found a way to prevent this error. I buffer the bluetooth actions and run them one by one. I don't know if this helps anyone?
    An example would be here: https://github.com/sepp89117/GoPro_Web_RC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions