You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GATT operation in progress - how to handle it? #188
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.
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.
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.
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.
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?
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.
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.
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.
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?
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.
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.
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.
#316 includes startNotifications() too, because I can't believe that writing characteristics needs serialization, but writing the CCC descriptor doesn't.
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.
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)
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
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?
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.
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
Activity
beaufortfrancois commentedon Nov 24, 2015
Are you testing this on Chrome OS or Android?
perja12 commentedon Nov 24, 2015
Testing this on Android (Chrome Dev build) and soon in Opera internal build.
beaufortfrancois commentedon Nov 24, 2015
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.
perja12 commentedon Nov 24, 2015
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.
beaufortfrancois commentedon Nov 24, 2015
Glad to hear that.
Hopefully @g-ortuno @scheib or @jyasskin will be able to fully answer your question here.
jyasskin commentedon Nov 24, 2015
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 callingwriteValue()again. If there's a good reason you can't do that, it would probably settle the argument.scheib commentedon Nov 24, 2015
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.
pzboyz commentedon Nov 26, 2015
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?
jyasskin commentedon Nov 26, 2015
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.g-ortuno commentedon Nov 30, 2015
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.
LeonNicholls commentedon Dec 7, 2015
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.
jyasskin commentedon Dec 7, 2015
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 progresserror. Is that something the implementation can guarantee with simpler code than just queuing everything?g-ortuno commentedon Dec 7, 2015
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 progresserrors since a Tab could get anin progresserror if another App is using bluetooth.8 remaining items
beaufortfrancois commentedon Oct 20, 2016
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.stopNotificationsis 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.
jyasskin commentedon Oct 20, 2016
I'm planning to add a statement that UAs MAY return a
NetworkErrorfor 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.jyasskin commentedon Oct 20, 2016
#316 includes
startNotifications()too, because I can't believe that writing characteristics needs serialization, but writing the CCC descriptor doesn't.g-ortuno commentedon Oct 20, 2016
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.
jyasskin commentedon Oct 20, 2016
If you're writing one characteristic, and you concurrently start notifications on another one, does that work?
beaufortfrancois commentedon Oct 21, 2016
FYI, with BlueZ, I get the error below:
Allow UAs to reject concurrent use of 6 functions. (#316)
Serialize calling of characteristic.writeValue in LayoutTests.
WayneKeenan commentedon Dec 23, 2017
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)
LiXi12 commentedon Aug 20, 2020
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
scheib commentedon Aug 20, 2020
@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.
nico-martin commentedon Sep 28, 2021
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?
scheib commentedon Sep 28, 2021
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.
beaufortfrancois commentedon Sep 29, 2021
For the record, we're discussing with as well at https://twitter.com/nic_o_martin/status/1443108799737483268
sepp89117 commentedon Dec 14, 2022
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