Closed
Bug 927038
Opened 11 years ago
Closed 11 years ago
Defect - Don't use Date.now as an ID
Categories
(Firefox for Metro Graveyard :: Browser, defect, P2)
Tracking
(Not tracked)
VERIFIED
FIXED
Firefox 28
People
(Reporter: Dolske, Assigned: kjozwiak)
References
Details
(Whiteboard: [block28] feature=defect c=tbd u=tbd p=1)
Attachments
(1 file, 1 obsolete file)
1.58 KB,
patch
|
mbrubeck
:
review+
|
Details | Diff | Splinter Review |
We've fixed a number of bugs (bug 925771, bug 586153, bug 578589) that were a result of using Date.now() as an identifier. The problem is that Date.now() can return the same value if called again in a sufficiently short period of time. [In the past Windows was the worst, as the result only changed ~60Hz].
I see a use of this in Metro:
browser/metro/base/content/bindings/browser.js
239 _deserializeHistoryEntry: function ...
...
258 if (aEntry.ID) {
259 // get a new unique ID for this frame (since the one from the last
260 // start might already be in use)
261 let id = aIdMap[aEntry.ID] || 0;
262 if (!id) {
263 for (id = Date.now(); id in aIdMap.used; id++);
264 aIdMap[aEntry.ID] = id;
265 aIdMap.used[id] = true;
266 }
267 shEntry.ID = id;
268 }
This seems especially sketchy since the loop in incrementing the timestamp, making a collision more likely in a future call.
It would be safer to use a simple static counter, or even nsIUUIDGenerator.
Updated•11 years ago
|
Component: General → Browser
OS: Mac OS X → Windows 8 Metro
Whiteboard: [triage]
Version: unspecified → Trunk
Updated•11 years ago
|
Blocks: metrov1backlog
Updated•11 years ago
|
Summary: Don't use Date.now as an ID → Defect - Don't use Date.now as an ID
Whiteboard: [triage] → feature=defect c=tbd u=tbd p=0
Updated•11 years ago
|
Whiteboard: feature=defect c=tbd u=tbd p=0 → [release28] feature=defect c=tbd u=tbd p=0
Assignee | ||
Comment 1•11 years ago
|
||
I will give this one a shot. Assigning it to myself.
Assignee: nobody → kamiljoz
Assignee | ||
Comment 2•11 years ago
|
||
Replaced Date.now() with nsIUUIDGenerator as suggested in comment #0.
Justin, would you mind taking a look and seeing if its done correctly? Thanks!
Attachment #828436 -
Flags: review?(dolske)
Reporter | ||
Comment 3•11 years ago
|
||
Comment on attachment 828436 [details] [diff] [review]
Replacing Date.now() with nsIUUIDGenerator
--> mbrubeck since this is Metro code
Attachment #828436 -
Flags: review?(dolske) → review?(mbrubeck)
Comment 4•11 years ago
|
||
Comment on attachment 828436 [details] [diff] [review]
Replacing Date.now() with nsIUUIDGenerator
Review of attachment 828436 [details] [diff] [review]:
-----------------------------------------------------------------
Thanks! One minor change suggested below to avoid a possible performance trap:
::: browser/metro/base/content/bindings/browser.js
@@ +259,5 @@
> // get a new unique ID for this frame (since the one from the last
> // start might already be in use)
> let id = aIdMap[aEntry.ID] || 0;
> if (!id) {
> + id = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID();
To avoid calling getService repeatedly, please add a global getter near the top of this file, like this:
XPCOMUtils.defineLazyServiceGetter(this, "gUUIDGenerator",
"@mozilla.org/uuid-generator;1", "nsIUUIDGenerator");
and then in this line you can write "id = gUUIDGenerator.generateUUID();"
Attachment #828436 -
Flags: review?(mbrubeck) → review+
Assignee | ||
Comment 5•11 years ago
|
||
Hi Matt,
Would you mind taking another quick look just to make sure it's correct now? Thanks again!
Attachment #828436 -
Attachment is obsolete: true
Attachment #829007 -
Flags: review?(mbrubeck)
Updated•11 years ago
|
Status: NEW → ASSIGNED
Priority: -- → P2
QA Contact: jbecerra
Whiteboard: [release28] feature=defect c=tbd u=tbd p=0 → [block28] feature=defect c=tbd u=tbd p=1
Updated•11 years ago
|
Attachment #829007 -
Flags: review?(mbrubeck) → review+
Comment 6•11 years ago
|
||
Target Milestone: --- → Firefox 28
Comment 7•11 years ago
|
||
Passed try here by the way:
https://tbpl.mozilla.org/?tree=Try&rev=9f2725af60ba
Comment 8•11 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Comment 9•11 years ago
|
||
Could anyone please give guidelines that can help the QA in verifying this issue? Thanks!
Flags: needinfo?(kamiljoz)
Comment 10•11 years ago
|
||
I think just go through the bugs listed in Comment 0 and verify that similar problems do not exist. You can also just check for regressions around history.
Updated•11 years ago
|
Flags: needinfo?(kamiljoz)
Comment 11•11 years ago
|
||
I don't think there was any user-visible bug here, since the old code *was* careful not to reuse IDs. This is just a code cleanup issue.
Status: RESOLVED → VERIFIED
Comment 12•11 years ago
|
||
Thanks Matt. I'll remove it from the testing sheet.
Updated•10 years ago
|
OS: Windows 8 Metro → Windows 8.1
You need to log in
before you can comment on or make changes to this bug.
Description
•