Closed Bug 2055233 Opened 17 days ago Closed 8 days ago

External links fail to open on cold launch on macOS (AppleEvents GURL blocked by TCC/Hardened Runtime timeout during session restore)

Categories

(Core :: Widget: Cocoa, defect)

Firefox 152
ARM64
macOS
defect

Tracking

()

RESOLVED FIXED
155 Branch
Tracking Status
firefox-esr140 --- unaffected
firefox-esr153 --- affected
firefox153 --- wontfix
firefox154 --- wontfix
firefox155 --- fixed

People

(Reporter: rgimadiyev, Assigned: emilio, NeedInfo)

References

(Regression)

Details

(Keywords: regression)

Attachments

(1 file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:152.0) Gecko/20100101 Firefox/152.0

Steps to reproduce:

  1. Set Firefox as your default browser on macOS.
  2. Enable "Restore previous session" in Firefox settings.
  3. Fully close Firefox (Cmd+Q).
  4. Click an external HTTP/HTTPS link in any other native macOS application.

Actual results:

Firefox launches, restores the previous session, and opens the clicked link in a new tab.

Expected results:

Firefox launches, restores the previous session, but the clicked link is completely ignored and lost.

There was an error in the description

Environment:

  • OS: macOS (15.x / 16.x)
  • Architecture: arm64 (Apple Silicon)
OS: Unspecified → macOS
Hardware: Unspecified → ARM64

The Bugbug bot thinks this bug should belong to the 'Core::Widget: Cocoa' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Widget: Cocoa
Product: Firefox → Core
Status: UNCONFIRMED → RESOLVED
Closed: 15 days ago
Duplicate of bug: 2036237
Resolution: --- → DUPLICATE

Donal Meehan [:dmeehan]

It's not fixed in 153.

(In reply to Rustam Himadiiev from comment #4)

Donal Meehan [:dmeehan]

It's not fixed in 153.

Thanks for flagging, reopening the bug, and setting Bug 1988774 as the regressor for further investigation

Status: RESOLVED → REOPENED
No longer duplicate of bug: 2036237
Ever confirmed: true
Keywords: regression
Regressed by: 1988774
Resolution: DUPLICATE → ---
See Also: → 2036237

:emilio, since you are the author of the regressor, bug 1988774, could you take a look? Also, could you set the severity field?

For more information, please visit BugBot documentation.

Flags: needinfo?(emilio)

Do we really know this is a regression from bug 1988774? I guess it does smell a lot like bug 2036237 indeed. I can reproduce on macOS, but not on a local build... Logan does this ring a bell?

Flags: needinfo?(emilio) → needinfo?(loganrosen)

Ah, I can repro in a local build but it's a bit harder because different default profiles...

Set release status flags based on info from the regressing bug 1988774

Emilio, are you looking into this?

Severity: -- → S2
Flags: needinfo?(emilio)

I confirmed this is a startup/session-restore ordering race. Firefox receives and briefly opens the Apple Event URL, but SessionStore then sees only the original about:home startup argument and restores with overwriteTabs: true, removing the new tab.

If the event arrives early enough to become a startup argument, or session restore is disabled, the URL survives. Deferring the pending-window handoff until SessionStore initializes also preserved both tabs in repeated testing.

Mozregression points to Bug 1988774, likely because the SDK change altered event timing. Bug 2036237 still fixed its original buffering issue; this is a separate session-restore interaction.

Flags: needinfo?(loganrosen)

So I added some logging to the application code, (basically dumping to a temporary file) and what I see in this case is something like this:

applicationWillFinishLaunching()
applicationDidFinishLaunching()
TakeStartupURLs()
StartupURLCollectionComplete()
openURLs(1)
openURLs [https://phabricator.services.mozilla.com/D311827]

So the StartupURLs stuff doesn't seem to be working as intended, instead, we call openURLs later, but session restore probably clobbers it? That happens even if I force overwriteTabs to false tho:

diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs
index 33d06eef09ac..ed8f101a7289 100644
--- a/browser/components/sessionstore/SessionStore.sys.mjs
+++ b/browser/components/sessionstore/SessionStore.sys.mjs
@@ -6011,7 +6011,7 @@ var SessionStoreInternal = {
    *        external link as well
    */
   restoreWindow: function ssi_restoreWindow(aWindow, winData, aOptions = {}) {
-    let overwriteTabs = aOptions && aOptions.overwriteTabs;
+    let overwriteTabs = aOptions && aOptions.overwriteTabs && false;
     let firstWindow = aOptions && aOptions.firstWindow;

     this.restoreSidebar(aWindow, winData.sidebar, winData.isPopup);

So this seems like at the very least a pre-existing race that could happen during startup.

Even without session-store enabled, I get:

applicationDidFinishLaunching()
TakeStartupURLs()
StartupURLCollectionComplete()
openURLs(1)
openURLs [https://phabricator.services.mozilla.com/D312766]

So it seems to me like:

  • The startup url stuff is not working at all.
  • Session restore races with a very eager openURLs which creates a remote command line here.

I'm not familiar with either of those things tho...

Flags: needinfo?(emilio)

Will keep digging but if anyone more familiar than me can it'd be greatly appreciated :)

Flags: needinfo?(emilio)

Ok now I'm seeing it work by just adding some log statements to the command line handler code, awesome.

So... My understanding is that the SDK update broke the whole StartupURLs mechanism. Bug 2036237 fixed the issue that when the openURLs calls arrived after the collection was complete they were just dropped on the floor rather than passed to the remote command line handler.

Logan does that match your understanding? Have you observed the StartupURLs mechanism work as intended after the SDK update?

Flags: needinfo?(emilio) → needinfo?(loganrosen)

(And now this bug should probably fix those URIs getting dropped or clobbered during session restore...)

Before the SDK update, macOS did the openURLs calls sync, before
applicationDidFinishLaunching, so applicationDidFinishLaunching was a
nice place to stop the app again.

However those calls are just posted to the event loop, so this mechanism
was not working at all.

Bug 2036237 fixed the opening of these urls so that they went through
the remote service instead of getting dropped, but that still races with
session restore, which looks at whether the command line was empty for
example.

This is the lower risk fix, which fixes this mechanism to wait for those
events. In order to do that without arbitrary timeouts, we just wait for
the event loop to idle.

There's a (maybe better) long term fix, which is removing this startup
url mechanism stuff altogether, handle all the openURLs method in the
remote service, and ensure session restore doesn't mess with them.

But that seems more annoying and risky, and this doesn't feel too
terrible? And it seems we might need the eager initialization anyways
for accessibility, so...

Assignee: nobody → emilio

Dave, I think you're familiar with our remote / command-line handling stuff... Could you take a look at:

There's a (maybe better) long term fix, which is removing this startup
url mechanism stuff altogether, handle all the openURLs method in the
remote service, and ensure session restore doesn't mess with them.

I didn't dig too much but when getting an openURLs call very early on, I didn't even get to handURItoExistingBrowser and co. Do you know if that's expected? I don't know when exactly BrowserContentHandler gets registered off the top of my head...

Flags: needinfo?(dtownsend)

I can look tomorrow, though this sounds very similar to bug 1600153.

Yeah I think that my patch effectively fixes bug 1600153 in another (maybe more minimal / less intrusive?) way

See Also: → 1600153

Yes, that matches what I observed. In the instrumented post-SDK cold launches I tested, application:openURLs: ran after TakeStartupURLs() / StartupURLCollectionComplete(), so the external LaunchServices URL was not captured by StartupURLs; I did not observe that mechanism working as intended after the SDK update.

With session restore disabled, the same URL still arrived through the later remote-command-line path and survived. That is consistent with bug 2036237 preventing the late URL from being dropped while leaving this session-restore race exposed. D313704 restores the intended startup collection ordering for this launch path.

Flags: needinfo?(loganrosen)
Status: REOPENED → RESOLVED
Closed: 15 days ago8 days ago
Resolution: --- → FIXED
Target Milestone: --- → 155 Branch

The patch landed in nightly and beta is affected, along with ESR.
:emilio, is this bug important enough to require an uplift?

For more information, please visit BugBot documentation.

Flags: needinfo?(emilio)

This has been shipping as is since bug 1988774 (FF 145) and is non-trivial so probably can ride the trains. Once it hits release we can try to uplift to ESR if we think it's worth it.

Regressions: 2058445
Duplicate of this bug: 1600153
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: