-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Remove the storage mutex #335
Comments
Indexed DB doesn't have the same problem. Connections and transaction scheduling is well defined (although there's no notification API). I'll take a peek at the storage mutex in HTML and comment if anything in worth salvaging. |
I wonder if @rocallahan still has plans for the perfect implementation of all this. |
No, I guess this ship has sailed. |
Sad trombone. @Ms2ger, what about Servo? |
I don't know if we've really considered it. CC @jdm. |
I have not put any effort into implementing an equivalent solution to the storage mutex in the spec. |
Yeah, looks fine to rip it all out, possibly with warnings about raciness sprinkled about. Definitely no impact to Indexed DB or SW's Cache. The bit about "the (Now would be a good time to solicit feedback on Origin Flags wouldn't it?) |
@inexorabletash you cannot hold that invariant without a mutex if you use independent processes for multiple same-origin tabs. (Unless perhaps all the storage is in its own process that uses an event loop of sorts. Perhaps that works?) |
Tabs could maintain snapshots of storage state which are updated only on return to the event loop. Again, I'm not sure if Chromium or other browsers actually do that in any/all cases. If we don't want to require such behavior, then we should call out that such an invariant doesn't hold. |
How would you reconcile conflicting updates, then? |
In Chrome, the source of truth for storage is in its own process. Tabs maintain local caches, observe updates that come in between ticks of the event loop (which in turn produce storage events), and send updates (last writer wins). |
Interesting. Is that for localStorage only, or cookies as well? Maybe we should specify that. |
The section "Serialisability of script execution" should be removed together with this. |
OK, so in #342 I have blindly removed the storage mutex. What kind of guidance should we add? The affected APIs are |
@rocallahan - re: cookies - they're different (in chrome) Getting There's no implicit synchronization mechanism like only updating state at the event loop, so it is possible for to observe cookie state changing during a script execution block. (I have sample code, but it's pretty obvious.) |
@inexorabletash do you think it's likely to be web compatible to have @rocallahan how do these APIs behave in Gecko, especially with multiprocess enabled? |
I don't know. @annevk might know, or might know who knows. |
Cookie setting and getting are synchronous operations from the child process to the parent, and there's no synchronization logic around updating when returning to the event loop. Storage is based around a process-local cache and async updates from the parent, so I would expect that to be stable during each turn of the event loop. |
@foolip - My guess is that it's web-compatible, given how subtle it is. It would change the behavior of That said, I don't think we'd rush to update the code here, although nailing this down before exposing a newfangled cookie API (e.g. to workers) would be a good idea and would merit revisiting the impl. |
So for For @inexorabletash said:
I did a very simple test: console.log(document.cookie);
document.cookie = 'foo=bar';
console.log(document.cookie); In Chromium, it looks like the second |
Note that |
Can't that be seen as just another source of unpredictable change, like another tab? |
Yeah, I guess that is fairly similar in that respect. |
I guess what's happening is that because the getter is sync, it'll block until the message for the async setter has been processed. Right, @inexorabletash? |
@foolip Right - async just means we don't wait for a response. Both sync and async IPC get onto the same queue in the receiver, so the async set is guaranteed processed before the async get. (That's implicit but there's even a comment in the code about that) |
OK, that means that the API will look synchronous to scripts. Do you think there is any combination multiple tabs, out-of-process iframes and communication with them where it could be observed that the setter is using async IPC? If not, it's very tempting to spec |
Add a stern warning for the racy document.cookies API. Fixes #335
Add a stern warning for the racy document.cookies API. Fixes #335
Add a stern warning for the racy document.cookies API. Fixes #335
Add stern warnings for both document.cookies and localStorage. Fixes #335
Note that I didn't try to spec how localStorage works at this point. If anyone thinks that could be made sane, or that it could be interoperably insane, please file a separate issue. |
The only thing that's somewhat weird is that now we have a warning on cookies, which looks good, but nothing for storage. I guess you did that because strategies differ in implementations. If that's the case, if you open up a new issue for storage so that defining that one way or another gets done in due course, I would be okay with merging this. |
There's a warning for storage analogous to the warning for cookies actually. |
I have filed #403 to actually define how |
Nobody has implemented the storage mutex. I think we should not pretend this will eventually happen. Instead we should supplement the spec with appropriate and detailed warnings about how cookies and local/session storage are prone to of multi-window corruption. Including some examples would be good.
If there are alternate patterns that we could recommend, that would be even better. But I think the same problem still occurs in e.g. IndexedDB? Or maybe transactions help there.
Tagging in @inexorabletash as a Blink storage person.
Related: #334 for removing the public API
navigator.yieldForStorageUpdates()
.The text was updated successfully, but these errors were encountered: