Open Bug 1157861 Opened 10 years ago Updated 3 years ago

Promise runnables can execute during synchronous XHR

Categories

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

defect

Tracking

()

REOPENED
Tracking Status
firefox40 --- affected

People

(Reporter: bdahl, Unassigned)

References

(Blocks 1 open bug)

Details

(Whiteboard: DUPEME)

Attachments

(1 file)

Attached file promise-race.html
The attached file has two functions that execute on the resolution of the same promise. Both functions should execute synchronously but they run interleaved when a synchronous XHR is used. STR: 1) Open the attached file 2) Look at console output, the array contains [ "A", "B", "B", "B", "B", "B", "A", "A", "A", "A" ] Expected Results: The array contains ["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"]
Whiteboard: DUPEME
And this one of the reasons why sync xhr is deprecated...
I was under the impression this has not been deprecated in workers though?
Does this happen in workers? It shouldn't.
Can you reproduce this with postMessage too? The debugger's "pausing" of the event loop had problems with Promise and also postMessage. Wouldn't be surprised if it was the same underlying bug here.
(In reply to Kyle Huey [:khuey] (khuey@mozilla.com) from comment #3) > Does this happen in workers? It shouldn't. It is fine in workers. I'll try with postMessage later.
Hmm, is this because Promises use different microtask setup than what MutationObservers do? For sync XHR MutationObserver has a "sync operation" flag on stack. I know, hackish, and doesn't work perfectly in all the cases, but the setup is somewhat similar to suppressing user events while sync XHR is running.
Whiteboard: DUPEME → DUPEME, [devtools-platform]
Now that we understand the problem a bit better: this is very likely a duplicate of bug 1145201. Promise runnables can still execute while the debugger is paused. The debugger uses the same mechanism to 'pause' the debuggee as synchronous XHR does, so if promises can still execute while the debugger is paused, it's to be expected that they can also execute during synchronous XHR. Fixing bug 1145201 should also fix this one. I'm going to mark this bug as a duplicate of that one, and add a comment over in the other bug that any fix we write should also be tested against synchronous XHR.
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → DUPLICATE
I'm going to re-open this, actually. The way we're going to fix bug 1145201 is not to beef up nsDOMWindowUtils::suppressEventHandling or nsDOMWindowUtils::suspendTimeouts, as comment 7 suggests. Instead, we need the Debugger API itself to save and restore the event queues, as explained in bug 1145201 comment 26. So addressing the Debugger's needs will not affect synchronous XHR, unfortunately. However, the solutions may be able to share code!
Status: RESOLVED → REOPENED
Resolution: DUPLICATE → ---
Whiteboard: DUPEME, [devtools-platform] → DUPEME
This particular bug was fixed in bug 1193394, which made Promises to use proper microtasks. See comment 6. But there can of course be some devtools specific issue still.
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: