Closed Bug 1585068 Opened 6 years ago Closed 6 years ago

Assertion failure: !mCx->mPendingUnhandledRejections.Lookup(promiseID), at xpcom/base/CycleCollectedJSContext.cpp:751

Categories

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

defect

Tracking

()

RESOLVED FIXED
mozilla71
Tracking Status
firefox-esr60 --- unaffected
firefox-esr68 --- unaffected
firefox67 --- unaffected
firefox68 --- unaffected
firefox69 --- wontfix
firefox70 --- wontfix
firefox71 --- fixed

People

(Reporter: bc, Assigned: emilio)

References

(Regression, )

Details

(4 keywords, Whiteboard: [MemShrink], [wptsync upstream])

Attachments

(4 files)

  1. https://www.t-online.de/unterhaltung/tv/id_86518080/-bares-fuer-rares-wie-haendler-lucki-77-ueber-den-tv-ruhestand-denkt.html and 8 other urls in the last week.

  2. Assertion failure: !mCx->mPendingUnhandledRejections.Lookup(promiseID), at /builds/worker/workspace/build/src/xpcom/base/CycleCollectedJSContext.cpp:751

Appears to assert on load. Bughunter reproduces on Linux and Windows on Nightly. I also reproduced on Beta so this is not an extremely recent regression if it is one at all.

S-S since CycleCollectedJSContext scares me.

Assertion failure: !mCx->mPendingUnhandledRejections.Lookup(promiseID), at /builds/worker/workspace/build/src/xpcom/base/CycleCollectedJSContext.cpp:751
#01: nsThread::ProcessNextEvent(bool, bool*) (/mozilla/builds/nightly/mozilla/firefox-debug/dist/bin/libxul.so)
#02: NS_ProcessNextEvent(nsIThread*, bool) (/mozilla/builds/nightly/mozilla/firefox-debug/dist/bin/libxul.so)
#03: mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) (/mozilla/builds/nightly/mozilla/firefox-debug/dist/bin/libxul.so)
#04: MessageLoop::RunInternal() (/mozilla/builds/nightly/mozilla/firefox-debug/dist/bin/libxul.so)
#05: MessageLoop::Run() (/mozilla/builds/nightly/mozilla/firefox-debug/dist/bin/libxul.so)
#06: nsBaseAppShell::Run() (/mozilla/builds/nightly/mozilla/firefox-debug/dist/bin/libxul.so)
#07: XRE_RunAppShell() (/mozilla/builds/nightly/mozilla/firefox-debug/dist/bin/libxul.so)
#08: mozilla::ipc::MessagePumpForChildProcess::Run(base::MessagePump::Delegate*) (/mozilla/builds/nightly/mozilla/firefox-debug/dist/bin/libxul.so)
#09: MessageLoop::RunInternal() (/mozilla/builds/nightly/mozilla/firefox-debug/dist/bin/libxul.so)

Edgar, how bad is this assertion? Thanks.

Group: core-security → dom-core-security
Component: XPCOM → DOM: Core & HTML
Flags: needinfo?(echen)

Hitting this assertion means the promise doesn't be removed from hashtable expectedly at a certain point and a leak could happen given that we won't have a chance to remove it again later. I tried to reproduce this with the URL provided in the above comment, but no luck.

Flags: needinfo?(echen)
Priority: -- → P2

I've reproduced with 2019-10-03 and with today's nightly on Fedora 30 with and without pop up blocking enabled. It asserts on load after a 10 seconds or so for me.

Group: dom-core-security
Keywords: memory-leak
Whiteboard: [MemShrink]

Edgar, I can repro this consistently, see bug 1585226 for STR. That requires a chromium tree around but I can provide you a zipfile with the relevant files otherwise.

FWIW I poked a bit at it and the "unhandled" flag was removed shortly after calling the tracker callback in:

(rr) p DumpJSStack()
0 promise_test/tests.promise_tests</<(resolve = [function], [function]) ["file:///home/emilio/src/chromium/src/third_party/blink/web_tests/resources/testharness.js":612:21]
    this = [object Window]
1 promise_test/tests.promise_tests<(undefined) ["file:///home/emilio/src/chromium/src/third_party/blink/web_tests/resources/testharness.js":590:19]
    this = [object Window]

$5 = void
Flags: needinfo?(echen)

Unfortunately gdb was choking when callink DumpJSStack() at this point so I don't have the JS stack.

This corresponds to the js stack pasted in my previous comment. In any case, it seems like it should be safe to just remove it from the hash table unconditionally? Though I don't know this code enough to be sure.

See Also: → 1585226

Oh, managed to get the js stack from comment 5, which is the same from comment 4.

Ah, the call in comment 5 is with State::Handled, but there is a previous call with State::Unhandled which adds it to the hash map for the same promise.

So probably the right thing to do is removing it from the map when we get the second Handled call, or something like that.

JS stack for the initial unhandled thing:

0 anonymous([object Object]) ["file:///home/emilio/src/chromium/src/third_party/blink/web_tests/gamepad/gamepad-polling-access.html":153:4]
1 Test.prototype.step(func = [function], this_obj = [object Object], [object Object]) ["file:///home/emilio/src/chromium/src/third_party/blink/web_tests/resources/testharness.js":1587:24]
this = [object Object]
2 promise_test/tests.promise_tests</<(resolve = [function], [function]) ["file:///home/emilio/src/chromium/src/third_party/blink/web_tests/resources/testharness.js":591:35]
this = [object Window]
3 promise_test/tests.promise_tests<(undefined) ["file:///home/emilio/src/chromium/src/third_party/blink/web_tests/resources/testharness.js":590:19]
this = [object Window]

This fixes it for me:

diff --git a/xpcom/base/CycleCollectedJSContext.cpp b/xpcom/base/CycleCollectedJSContext.cpp
index e63a286681be..9a8e6d33cd18 100644
--- a/xpcom/base/CycleCollectedJSContext.cpp
+++ b/xpcom/base/CycleCollectedJSContext.cpp
@@ -367,8 +367,7 @@ void CycleCollectedJSContext::PromiseRejectionTrackerCallback(
     }
   } else {
     PromiseDebugging::AddConsumedRejection(aPromise);
-    if (mozilla::StaticPrefs::dom_promise_rejection_events_enabled() &&
-        !aMutedErrors) {
+    if (mozilla::StaticPrefs::dom_promise_rejection_events_enabled()) {
       for (size_t i = 0; i < aboutToBeNotified.Length(); i++) {
         if (aboutToBeNotified[i] &&
             aboutToBeNotified[i]->PromiseObj() == aPromise) {
@@ -383,7 +382,7 @@ void CycleCollectedJSContext::PromiseRejectionTrackerCallback(
       }
       RefPtr<Promise> promise;
       unhandled.Remove(promiseID, getter_AddRefs(promise));
-      if (!promise) {
+      if (!promise && !aMutedErrors) {
         nsIGlobalObject* global = xpc::NativeGlobal(aPromise);
         if (nsCOMPtr<EventTarget> owner = do_QueryInterface(global)) {
           RootedDictionary<PromiseRejectionEventInit> init(aCx);

Not sure if it's right though.

Here's a trivial test-case that asserts:

<!doctype html>
<script src="testing/web-platform/tests/resources/testharness.js"></script>
<script>
promise_test(async () => {
  somethingThatDoesNotExist()
}, "Bar");
</script>

For some reason just inlining the testharness.js thing in a script doesn't crash, weird.

Assignee: nobody → emilio

For some reason the crashtest works if ran locally like:

./mach run dom/base/crashtests/1585068.html

But not from the crashtest suite. I assume the "muted errors" path is only for
remote (not same-origin) scripts? (and that's why it didn't trigger in regular
wpt?).

Any good way to test this in that case?

Okay, so the promise was rejected in the current script and then being handled in a cross-origin script., I missed this possibility while I tried to write some tests to reproduce it. Thank you, Emilio!!!

Flags: needinfo?(echen)

Bugbug thinks this bug is a regression, but please revert this change in case of error.

Keywords: regression
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/cd16bcbc7025 Cleanup rejections even if errors are muted. r=edgar,smaug https://hg.mozilla.org/integration/autoland/rev/303f2802f3e8 Add WPT for promise rejections event for cross-origin script; r=smaug
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/19700 for changes under testing/web-platform/tests
Whiteboard: [MemShrink] → [MemShrink], [wptsync upstream]
Upstream web-platform-tests status checks passed, PR will merge once commit reaches central.
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla71
Upstream PR merged by moz-wptsync-bot
Regressed by: 1549351
Has Regression Range: --- → yes
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: