Closed Bug 987682 Opened 10 years ago Closed 10 years ago

DumpBookmarks() in bookmarks.jsm hangs due to invalid JSON data

Categories

(Testing Graveyard :: TPS, defect)

defect
Not set
normal

Tracking

(firefox29 wontfix, firefox30 fixed, firefox31 fixed)

RESOLVED FIXED
mozilla31
Tracking Status
firefox29 --- wontfix
firefox30 --- fixed
firefox31 --- fixed

People

(Reporter: whimboo, Assigned: whimboo)

References

Details

Attachments

(1 file)

The DumpBookmarks() method in bookmarks.jsm fails because of a broken promise handling which causes the JSON data to be empty (invalid). That's why an exception gets raised and cb.wait() is never called.

http://mxr.mozilla.org/mozilla-central/source/services/sync/tps/extensions/tps/resource/modules/bookmarks.jsm#23

The problem here is that the call to BookmarkJSONUtils.serializeNodeAsJSONToOutputStream() doesn't stop the execution of the task as is should given the yield keyword. So writer.value has still its initial value '', and JSON.parse('') causes an exception.

You can see that when adding dump() statements to writer.write() and after the yield line.

Marco, do you have an idea what could go wrong here?
Flags: needinfo?(mak77)
By any chance, could we take the opportunity to get rid of this cb.wait()?
TPS is handling everything synchronously. So there is no easy way to do that. Anything else which would help here?
Why exactly is TPS handling everything synchronously, I wonder?
Jgriffin has written TPS. So he can tell more. As of now we don't have the time to entirely rewrite tps. We have to get all the tests working, and this is somewhat a blocker for me.
Here the minimized code which should return a serialized JSON string for the bookmarks. Instead it is empty.

Components.utils.import("resource://gre/modules/BookmarkJSONUtils.jsm");

let writer = {
 value: "",
 write: function PlacesItem__dump__write(aStr, aLen) { this.value += aStr; }
};

let options = PlacesUtils.history.getNewQueryOptions();
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
let query = PlacesUtils.history.getNewQuery();
query.setFolders([PlacesUtils.placesRootId], 1);
let root = PlacesUtils.history.executeQuery(query, options).root;
root.containerOpen = true;

BookmarkJSONUtils.serializeNodeAsJSONToOutputStream(root, writer, true, false).then(() => {
  window.alert(writer.value);
});
Actually, I would like to completely kill serializeNodeAsJSONToOutputStream API, it sucks and we are not going to spend time on it.

In this case looks like you want to just dump all of the bookmarks, basically dump the bookmarks.json... you should then use the new getBookmarksTree() util and json.stringify the bookmarks object out of it
Flags: needinfo?(mak77)
Blocks: 970291
Sounds fair enough. I will remove it. The alternative works perfectly. Thank you Marco!
Assignee: nobody → hskupin
Status: NEW → ASSIGNED
Attached patch Patch v1Splinter Review
This patch fixes the hang and also makes sure that we do not hang anymore in case an exception gets thrown inside of the then method. Given that the output it not that important we should not call cb(ex) but simply log the error message to the console.
Attachment #8396511 - Flags: review?(jgriffin)
Ups, kill the last sentence. It's not what the patch contains. If you want that please feel free to request. I would be happy with cb(ex) given that it should not fail.
The remaining hangs in cb.wait() I will get fixed in bug 981848.
Blocks: 981848
Comment on attachment 8396511 [details] [diff] [review]
Patch v1

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

It probably makes sense to log the error, but I don't have a strong opinion, since as you said, the error isn't really important to TPS.
Attachment #8396511 - Flags: review?(jgriffin) → review+
Target Milestone: --- → mozilla31
https://hg.mozilla.org/mozilla-central/rev/893c003daf13
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Andrei, can you please verify this fix? I would like to get it backported, but I would like to see at least one other confirmation it works correctly. And given that you also have seen this bug yesterday... Thanks.
I confirm that I don't see any more hangs with this fix.
Comment on attachment 8396511 [details] [diff] [review]
Patch v1

[Approval Request Comment]
Bug caused by (feature/regressing bug #): None
User impact if declined: None, but automated tests will hang
Testing completed (on m-c, etc.): yes
Risk to taking this patch (and alternatives if risky): None
String or IDL/UUID changes made by this patch:None

The backport for beta would need a new patch given that the new method used here, will not be available. But for now we are not clear, if we need this backport at all.
Attachment #8396511 - Flags: approval-mozilla-aurora?
Attachment #8396511 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Product: Testing → Testing Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: