Closed Bug 1528319 Opened 2 years ago Closed 1 year ago

Reloading after creating AudioContext causes InvalidStateError


(Core :: Web Audio, defect, P2)

63 Branch



Tracking Status
firefox-esr60 --- unaffected
firefox65 --- wontfix
firefox66 --- wontfix
firefox67 + verified
firefox68 --- verified


(Reporter: omgitsraven, Assigned: padenot)



(Keywords: regression)


(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0

Steps to reproduce:

  1. Visit a page containing a script tag that contains "new AudioContext()", i.e.:
  2. Open the console
  3. Reload the page

Actual results:

A red error appears, saying " InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable"

Expected results:


For a slightly more complex example: Here the AudioContext is only created if the text is clicked, and in that case, the error only appears when reloading after having clicked the text, not when reloading after having done nothing.

Component: Untriaged → Web Audio
Product: Firefox → Core
Ever confirmed: true
Keywords: regression
Version: 65 Branch → 63 Branch

Regression window:

Suspect: Bug 1486130

Your bunch of patch seems to cause the error message.
Can you please look into this?

Blocks: 1486130
Flags: needinfo?(kmaglione+bmo)

My patch does not cause the error. It just stops it from being hidden.

Flags: needinfo?(kmaglione+bmo)
No longer blocks: 1486130
Priority: -- → P2

Karl, who is the best assignee for this bug?

Flags: needinfo?(karlt)

This is the stack generating the unhandled rejected promise.

#8 0x00007fd8ce466c35 in mozilla::dom::Promise::MaybeReject(nsresult)
(this=0x7fd8c94a5460, aArg=-2142044149)
at /var/karl/moz/obj/dist/include/mozilla/dom/Promise.h:94
#9 0x00007fd8d2b07a60 in mozilla::dom::AudioContext::Shutdown()
at /home/karl/moz/dev/dom/media/webaudio/AudioContext.cpp:716
#10 0x00007fd8d05bd3e1 in nsGlobalWindowInner::FreeInnerObjects()
at /home/karl/moz/dev/dom/base/nsGlobalWindowInner.cpp:1162
#11 0x00007fd8d0601193 in nsGlobalWindowOuter::SetNewDocument(mozilla::dom::Document*, nsISupports*, bool)
(this=0x7fd8c96bf4c0, aDocument=0x7fd8c78f1000, aState=0x0, aForceReuseInnerWindow=false) at /home/karl/moz/dev/dom/base/nsGlobalWindowOuter.cpp:2242

I assume this is the ignored promise from the Close() above.

If the promise is ignored, then perhaps the MaybeReject() loop can be moved to before the Close() call.

"global is going away soon" sounds similar to this situation, but I don't know much about that:

Paul, do you know whether this situation is related to bug 1325215?

Flags: needinfo?(karlt) → needinfo?(padenot)

(In reply to Karl Tomlinson (:karlt) from comment #4)

Paul, do you know whether this situation is related to

bug 1343550, I meant.

This is done in the same style as ::Suspend and ::Resume.

Thanks for the analysis, Karl.

Flags: needinfo?(padenot)
Assignee: nobody → padenot
Pushed by
Don't create a Promise when shutting down an AudioContext. r=karlt
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68

Hi Paul, since 67 is marked as affected, should we consider uplifting this to Beta67?

Flags: needinfo?(padenot)

Comment on attachment 9052872 [details]
Bug 1528319 - Don't create a Promise when shutting down an AudioContext. r=karlt

Beta/Release Uplift Approval Request

  • Feature/Bug causing the regression: Bug 1486130
  • User impact if declined: Bug 1486130 made it so that the error stopped being hidden. It's quite benign, but can also be puzzling for developers: it's seemingly an error that only happens during the onloading of a document, but the console persists between reload, so it looks like an error at loading a bit.
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): This is doing the same thing we've been doing for quite some time on the two other methods for the same feature (suspend/resume/close, this is handling the close bit), and we never had any issues with the other ones.
  • String changes made/needed:
Flags: needinfo?(padenot)
Attachment #9052872 - Flags: approval-mozilla-beta?

[Tracking Requested - why for this release]:
Paul has posted a patch for beta uplift in comment 11.

Flags: needinfo?(pascalc)
Flags: needinfo?(pascalc)

Comment on attachment 9052872 [details]
Bug 1528319 - Don't create a Promise when shutting down an AudioContext. r=karlt

Well understood fix affecting web developers working with audio only, verified on Nightly, uplift approved for 67 beta 7 thanks.

Attachment #9052872 - Flags: approval-mozilla-beta? → approval-mozilla-beta+

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0
Build ID: 20190331141835

Verified as fixed using the latest DevEdition Build and the latest Nightly Build (20190402083512). The Error is no longer displayed in the Console.

Flags: qe-verify+
Regressions: 1549041
You need to log in before you can comment on or make changes to this bug.