Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property updating should be atomic #8

Closed
yutakahirano opened this issue Jul 5, 2022 · 3 comments
Closed

Property updating should be atomic #8

yutakahirano opened this issue Jul 5, 2022 · 3 comments
Labels
api Issue with API specs

Comments

@yutakahirano
Copy link

yutakahirano commented Jul 5, 2022

We have several properties (url, method, ...) which can be updated independently. This is not good from two reasons.

  1. The user agent may start sending data while we are updating properties (see also: When the user agent sends data should be clarified #7).
  2. The page may crash while updating properties.

Let's think about (2) as it's simpler.

let beacon = new PendingBeacon(url, {method, data});
...
// (p)
beacon.url = newUrl;
// (q)
beacon.method = newMethod.
// (r)
beacon.setData(newData);
// (s)

A page may crash at any timing, so with the current API the web developer need to deal with four possibilities. This can be pretty confusing, because by nature analyzing crash reports is hard and complex.

crash point url method data
(p) url method data
(q) newUrl method data
(r) newUrl newMethod data
(s) newUrl newMethod newData

While (q) and (r) are rare, all can happen. For multi-process implementations such as Chrome, the possibility grows when the system is busy, because of IPC latency.

We can address this problem by making the modification atomic.

let beacon = new PendingBeacon(url, {method, data});
...
// (X)
beacon.update({url: newUrl, method: newMethod, data: newData});
// (Y)

Now we have only two possibilities.

crash point url method data
(X) url method data
(Y) newUrl newMethod newData
@fergald
Copy link
Collaborator

fergald commented Jul 5, 2022

I'm not sure that we have any use case for changing any property after construction. Unless we get a concrete request for that capability, I'd suggest that all properties should be set at construction time and immutable after that.

@yutakahirano
Copy link
Author

Sounds reasonable, thank you!

mingyc added a commit that referenced this issue Jul 5, 2022
@mingyc mingyc added the api Issue with API specs label Jul 6, 2022
aarongable pushed a commit to chromium/chromium that referenced this issue Jul 7, 2022
This change does the following
- Make all PendingBeacon's property readonly per [discussion][1]
- Replace `state` with `isPending`
- Update links to explainer doc.

[1]: WICG/pending-beacon#8

Bug: 1293679
Change-Id: I4fbcee7b436cc9ed22775433b00f5d85ead9d9e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3743630
Reviewed-by: Yutaka Hirano <[email protected]>
Commit-Queue: Ming-Ying Chung <[email protected]>
Reviewed-by: Rakina Zata Amni <[email protected]>
Reviewed-by: Matthew Denton <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1021516}
@jdfreder
Copy link
Contributor

I don't think it's to far fetched to want to update query args on the URL, for systems that still rely on query args instead of HTTP body. Additionally, I'm not convinced that we'd need an atomic operation to update multiple properties (I would expect the failures you mention in the case above, and not expect the browser to mitigate that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue with API specs
Projects
None yet
Development

No branches or pull requests

4 participants