On Wed, Dec 2, 2009 at 2:06 AM, Ian Hickson <span dir="ltr"><<a href="mailto:ian@hixie.ch">ian@hixie.ch</a>></span> wrote:<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">


On Tue, 3 Nov 2009, Jeremy Orlow wrote:<br>
><br>
> If we do this, we need to re-visit ways that scripts can tell whether<br>
> the lock has been dropped.  I can't remember which idea was most in<br>
> favor last time we talked about it, but a counter that increments every<br>
> time LocalStorage is unlocked sticks out in my mind.  (Scripts can check<br>
> the counter, do something that could cause unlocking, and then verify<br>
> the counter is still the same after.)<br>
<br>
The counter could be a boolean -- does the event loop have the lock [for<br>
the origin of the first script]. I would recommend implementing this as<br>
a property window.navigator.webkitStorageUpdatesLocked which is true when<br>
the lock is obtained and false when it is released. If people find it<br>
useful, we can add it to the language.<br></blockquote><div><br></div><div>If it's a boolean, it's possible that it was implicitly unlocked and then re-locked.  If you have a counter, you can simply check that the count is the same as when you started.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
> Another option that just came to mind is to have some flag that says<br>
> "throw an exception whenever there's been a serialization violation".<br>
<br>
Could you elaborate on this?<br></blockquote><div><br></div><div>You'd have some boolean property that defaults to false (say navigator.throwOnStorageMutexDeadlocks) that when set to true would cause an exception to be thrown either immediately or the next time you try to do a localStorage operation before either calling navigator.yieldForStorageUpdates or the task ending.</div>

<div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On Wed, 25 Nov 2009, Jeremy Orlow wrote:<br>
><br>
> I know that we've discussed approximations of run to completion before,<br>
> but maybe it's worth one more shot:  What if on the first use of<br>
> document.cookie or local storage we took a snapshot of both and used<br>
> that during the task's execution.  All writes would be queued up until<br>
> the task finishes, at which point they'd be written to the central<br>
> version of the cookie and/or local storage.  This would provide a<br>
> consistent view of data for the duration of the task and would solve<br>
> almost all the atomicity problems except |document.cookie =<br>
> document.cookie + "foo";|.  For that, I'd suggest adding a method that<br>
> allows scripts to do atomic modifications to storage within a callback.<br>
><br>
> I can understand everyone's desire to have completely serializable<br>
> semantics for local storage access and cookies (if you don't count the<br>
> servers' interaction with them), but maybe we need to go back to use<br>
> cases.  In a world with WebDatabase/WebSimpleDB, I really don't see<br>
> anyone turning to LocalStorage except for more basic uses.  Most of<br>
> which I'm guessing need consistent reads much more than serialization of<br>
> everything.<br>
><br>
> And let's be realistic.  IE has had this problem with document.cookie<br>
> for a long time.  And IE8 now has this problem with localStorage.<br>
> Given that in the best case (MS and all others implement the storage<br>
> mutex) web developers will not be able to assume localStorage and<br>
> document.cookie access is atomic for many years at a minimum, I think<br>
> we're being pretty unrealistic about how much the storage mutex is going<br>
> to improve anyone's life.  Let's come up with an approximation, give<br>
> developers a callback for atomic access, and be done with it.<br>
<br>
As far as I can tell, this wouldn't remove race problems. It would in fact<br>
make it impossible to avoid them, since as far as I can tell you can't<br>
build a sane locking mechanism based on the above.<br></blockquote><div><br></div><div>I don't understand what you mean by building a sane locking mechanism.</div><div><br></div><div>The idea is that we'd have near-run-to-completion semantics when using local storage normally (via repeatable reads semantics on localStorage and document.cookie) and actual run-to-completion semantics (serializable) if you use the callback based mechanism for localStorage access.</div>

<div><br></div><div>Given that network based cookie access is essentially repeatable read semantics and both cookie and localStorage in IE and Chrome aren't even that currently, I'd say that such semantics seem good enough.  The fact that Chrome has never gotten any complaints about the racy behavior of its current document.cookie implementation is some evidence to support that.</div>

<div><br></div><div>J</div></div>