Closed Bug 715700 Opened 13 years ago Closed 12 years ago

localStorage gets out of sync in Private Mode

Categories

(Core :: DOM: Core & HTML, defect)

9 Branch
x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla12
Tracking Status
firefox10 - ---
firefox11 - ---
firefox12 + verified

People

(Reporter: colin, Assigned: jdm)

References

Details

(Keywords: regression, Whiteboard: [qa+])

Attachments

(3 files, 1 obsolete file)

Attached file Test page.
This may be the same bug as 662511, however, that bug has already been closed and this one has a simpler test case.

When using localStorage in private browsing, if you open the same page in a second window, or open a different page in the same window, and then write to localStorage, anything that was already in localStorage is lost. This problem can be avoided by reading from localStorage (or just referencing localStorage.length) first.

Save the attachment as test1.html and test1a.html and then:

1. Go into private browsing mode.

2. Load test1.html.

3. Enter "test1" and "value1" and hit SAVE.

4. Click on "DUMP" to verify that the data was saved to localStorage.

5. Load test1a.html.

6. Enter "test2" and "value2" and hit SAVE.

7. Click on "DUMP" and you'll ONLY see "test2". Test1 has gone (although it can still be accessed via localStorage.getItem("test1")).

If you repeat the test but BEFORE step 6 click on the GET LENGTH button, then after saving the test2 data when you click on DUMP you'll see both values.
This problem does NOT occur on Firefox 8, but does occur with Firefox 9.
Thanks! Since you're able to reproduce this problem, could you help us find a regression range? http://mozilla.github.com/mozregression/ is a tool that will help you narrow the problem down to an isolated range. Just give it 2011-09-27 for the good date, and 2011-11-08 for the bad one (those should correspond to the dates for FF8 and FF9), and we should be able to find a specific nightly build in which this bug appeared.
What a GREAT tool!!

Last good nightly: 2011-09-23
First bad nightly: 2011-09-24
From the range of http://hg.mozilla.org/mozilla-central/pushloghtml?startdate=2011-09-23&enddate=2011-09-24, bug 683316 looks like the most likely candidate. I'll put together a build without that change so we can test that theory.
Yes, that's the only thing in the changelog http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=259d1556c221&tochange=c71229984353 which mentions "storage".
In a couple hours, there will be a testing build available at http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/josh@joshmatthews.net-d879e0e35fc1 . Give it a shot and see if this bug disappears.
No more bug. That checkin was the culprit.
Thanks for confirming that, Colin!
Blocks: 683316
Any idea when this will get fixed? localStorage not working in Private Mode is quite a regression.
Tracking for FF10 and higher since this is a recent regression. We'll still evaluate the risk vs reward once fixed, as the user scenario that this occurs in (Private Mode + LocalStorage) sounds fairly uncommon.
Sending over to jst to see if somebody can take a look at this. To be clear on the tracking flags, I see no reason to block FF10/11 release due to this bug (fairly low user pain). Since it is a recent regression, however, I'd like to make sure we investigate further.
Assignee: nobody → jst
Sorry, I forgot to make clear that Honza asked me to look into this, and I am doing so.
Assignee: jst → josh
The same problem is exhibited outside of private browsing if sessionStorage is used instead of localStorage. nsDOMStoragePersistentDB explicitly caches all keys inside SetKey, while nsDOMStorageMemoryDB does not. However, I'm having trouble writing a mochitest that demonstrates this - using an iframe caused the bug to be hidden (maybe something about the store being cloned?), and a popup window turned out to exhibit different behaviour than I was expecting, and I haven't figured out whether it's correct yet or not.
Ugh, my mistake for not understanding how sessionStorage works. I expect most or all of comment 13 can be ignored.
Attachment #587885 - Flags: review?(honzab.moz)
Attachment #587886 - Attachment is obsolete: true
Attachment #587886 - Flags: review?(honzab.moz)
Comment on attachment 587885 [details] [diff] [review]
Cache all keys when setting a value in memory DBs

Review of attachment 587885 [details] [diff] [review]:
-----------------------------------------------------------------

Yes, that's it.  Thanks.

I think the yet better solution here is to move call of CacheKeysFromDB() from nsDOMStoragePersistentDB::SetKey to DOMStorageImpl::SetDBValue (before call of gStorageDB->SetKey).

For the record: the reason we are our out of sync is because of the following call stack:

>	xul.dll!DOMStorageImpl::SetCachedVersion(unsigned __int64 version=5)  Line 275	C++
 	xul.dll!nsDOMStorageBaseDB::MarkScopeDirty(DOMStorageImpl * aStorage=0x0b0bf7c0)  Line 95	C++
 	xul.dll!nsDOMStorageMemoryDB::SetKey(DOMStorageImpl * aStorage=0x0b0bf7c0, const nsAString_internal & aKey={...}, const nsAString_internal & aValue={...}, bool aSecure=false, int aQuota=5242880, bool aExcludeOfflineFromUsage=true, int * aNewUsage=0x0049bad4)  Line 240	C++
 	xul.dll!nsDOMStorageDBWrapper::SetKey(DOMStorageImpl * aStorage=0x0b0bf7c0, const nsAString_internal & aKey={...}, const nsAString_internal & aValue={...}, bool aSecure=false, int aQuota=5242880, bool aExcludeOfflineFromUsage=true, int * aNewUsage=0x0049bad4)  Line 166 + 0x78 bytes	C++
>	xul.dll!DOMStorageImpl::SetDBValue(const nsAString_internal & aKey={...}, const nsAString_internal & aValue={...}, bool aSecure=false)  Line 926 + 0x4b bytes	C++
 	xul.dll!DOMStorageImpl::SetValue(bool aIsCallerSecure=false, const nsAString_internal & aKey={...}, const nsAString_internal & aData={...}, nsAString_internal & aOldValue={...})  Line 1236 + 0x1a bytes	C++
 	xul.dll!nsDOMStorage::SetItem(const nsAString_internal & aKey={...}, const nsAString_internal & aData={...})  Line 1659 + 0x30 bytes	C++


This sets the version of data held by the instance wrongly to the latest (up-tp-date) version because of trust that the instance's cache is up to date.  But it is not, if we call SetItem on a brand new localStorage instance, because of missing call to CacheKeysFromDB().

How I'd love to remove this code completely!
Attachment #587885 - Flags: review?(honzab.moz) → review+
Attachment #587887 - Flags: review?(honzab.moz) → review+
https://hg.mozilla.org/mozilla-central/rev/740578328b88
https://hg.mozilla.org/mozilla-central/rev/4053b191975d
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla12
This hasn't caused significant user pain since FF10 was released - we'll let this ride the trains.
Whiteboard: [qa+]
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0

Verified on Windows 7 in Firefox 12 beta 4 using steps in comment 0. both values (test 1 and 2) are remembered now when selecting Dump in Private browsing mode.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: