Closed Bug 1543990 Opened 5 years ago Closed 11 months ago

Regression in Firefox 66: <link rel="preconnect"> no longer working

Categories

(Core :: Networking, defect, P1)

66 Branch
Desktop
Windows 10
defect

Tracking

()

RESOLVED FIXED
115 Branch
Performance Impact high
Tracking Status
firefox115 --- fixed

People

(Reporter: jakub.g.opensource, Assigned: kershaw)

References

(Blocks 3 open bugs)

Details

(Whiteboard: [necko-triaged])

Attachments

(7 files, 1 obsolete file)

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

Steps to reproduce:

Open https://jg-testpage.github.io/wpt/preconnect.html in Firefox 66

It contains <link rel="preconnect"> + setTimeout(1000) HTTP request

Actual results:

<link rel="preconnect"> was ignored, and DNS+TCP+TLS happened at the HTTP request time

From my tests with devtools it seems it was working until Firefox 65 (see attachment)

Expected results:

DNS+TCP+TLS should have happened earlier

Firefox 66 KO https://www.webpagetest.org/result/190411_12_ed5cfb727a48dcea11b1a4f54999922c/1/details/

Firefox 68 Nightly KO https://www.webpagetest.org/result/190411_T3_3cb066d3ceb1fbd2be1bf33cfb491bf5/1/details/

Chrome OK https://www.webpagetest.org/result/190412_AQ_147b2535813e4324497d471e22d67445/1/details/

Component: Untriaged → Networking
OS: Unspecified → Windows 10
Product: Firefox → Core
Hardware: Unspecified → Desktop

Hmm it seems to be KO also on Firefox 60 ESR on WebPageTest which is quite surprising to me:

https://www.webpagetest.org/result/190412_VW_914427d9be5121b7bab6fac7c054ea64/1/details/#waterfall_view_step1

I was thinking that since Firefox ESR always reports "60.0" in useragent string, it could be that WPT has ESR v60.6 which may contain the faulty code from Firefox 66, but I tested 60.6 ESR locally and it is not affected.

Assignee: nobody → dd.mozilla
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Priority: -- → P3
Whiteboard: [necko-triaged]
Assignee: dd.mozilla → nobody
Status: ASSIGNED → NEW

If someone takes this bug, note that test methodology is important to repro correctly: if you repeat the test (refresh the page), you won't repro the issue anymore, because the browser maintains the connection open for some number of seconds.

The ideal test methodology is:

1 Close the test URL tab (to make sure it doesn't reload automatically on browser restart)
2 Close the browser (to clean the connection pool)
3 Optionally, clear DNS cache of the operating system
4 Reopen the browser
5 Open a new tab
6 Open devtools (to make sure you capture all the network requests)
7 Load test URL

Attached image ff87-no-preconnect.png

This is still a bug in Firefox 87. <link> Preconnect is non-functional in FF 87.

When well used, preconnect can help enhance the user experience, so fixing this would be really great. 🙏

Severity: normal → S3

As of FF version 105, it is still not working.

Thanks for reporting this one and to the folks following up.
This should be fixed with Bug 1813618, I'll verify once it has landed.

Flags: needinfo?(acreskey)
Depends on: 1813618
Flags: needinfo?(acreskey)
See Also: → 1816678

Performance impact set as high due to widespread use on the web.

Performance Impact: --- → high

The severity field for this bug is set to S3. However, the Performance Impact field flags this bug as having a high impact on the performance.
:valentin, could you consider increasing the severity of this performance-impacting bug? Alternatively, if you think the performance impact is lower than previously assessed, could you request a re-triage from the performance team by setting the Performance Impact flag to ??

For more information, please visit auto_nag documentation.

Flags: needinfo?(valentin.gosu)

I propose that this is Priority 1 (definitely want), and S2 (high impact, no workaround).

Severity: S3 → S2
Priority: P3 → P1
Flags: needinfo?(valentin.gosu)

This still depends on bug 1813618 being fixed.
Assigning the bug to myself to silence the autonag bot.

Assignee: nobody → valentin.gosu

With Bug 1813618 fixed, I would expect to see rel=preconnect functioning.

I'm using a test based on jakub.g's:
https://acreskeymoz.github.io/preconnect.html
and a variation without the preconnect: https://acreskeymoz.github.io/no_preconnect.html

However while I can see the speculative connect (and resulting DNS, TCP, TLS) begin upon reading the preconnect, as far as I can tell, we do this all over again when the actual resource load is requested.
And so no improvement is visible.

Here's a profile, preconnect to https://www.wikipedia.org, and later on load an image from that host.
https://share.firefox.dev/44ghCNz

And one where I load the site without the rel=preconnect
https://share.firefox.dev/44k7O55
I can see that there is no initial speculative connect, but the resource load time and time to fully loaded are not improved.

I'm using traffic shaping to increase my network latency so that any differences are more visible.

I do see this log during the resource load in the preconnect scenario,

GetH2orH3ActiveConn() request for ent 12ceed910 .S........[tlsflags0x00000000]www.wikipedia.org:443^partitionKey=%28https%2Cacreskeymoz.github.io%29 did not find an active connection 

So maybe we are making a new connection for some reason.

nsHttpConnectionMgr::OnMsgSpeculativeConnect [ci=.S.......[tlsflags0x00000000]www.wikipedia.org:443^partitionKey=%28https%2Cwikipedia.org%29, mFetchHTTPSRR=1]

Indeed, it seems that the preconnect is using the origin of the link, instead of the top level domain (acreskeymoz.github.io) when loaded via rel=preconnect so it ends up not being used.

The code this is coming from doesn't seem immediately wrong, so probably the issue is somewhere deeper in Necko.

I think the problem is at this line.
Since we passed the URI of link header (www.wikipedia.org) to the function UpdateOriginAttributesForNetworkState, we get the the partition key partitionKey=%28https%2Cwikipedia.org%29 and we create a speculative connection with the key .S........[tlsflags0x00000000]www.wikipedia.org:443^partitionKey=%28https%2Cacreskeymoz.github.io%29. However, what we should pass to UpdateOriginAttributesForNetworkState is the first party URI, not the one in link header. I think the correct first party URI here is acreskeymoz.github.io.

Thank you Valentin and nicely done, Kershaw.
With your patch I can confirm that rel=preconnect is now working as expected with this profile: https://share.firefox.dev/3HAWgkm
looking at https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2@2x.png

Attached image preconnect.png

The dev tools highlight the improvement, here with preconnect.

Attached image no_preconnect.png

And without preconnect.

Whiteboard: [necko-triaged] → [necko-triaged][necko-priority-next]

In code review we discovered that the solution is a little more complicated but we expect to fix this shortly.

Duplicate of this bug: 1813071

Take this from Valentin, since I am working on this.

Assignee: valentin.gosu → kershaw
Attachment #9331392 - Attachment is obsolete: true
Whiteboard: [necko-triaged][necko-priority-next] → [necko-triaged]
Blocks: 1836053
Pushed by kjang@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/89a8aa4b8d28
Simplify nsISpeculativeConnect API, r=necko-reviewers,geckoview-reviewers,search-reviewers,valentin,m_kato
https://hg.mozilla.org/integration/autoland/rev/f1280b2e8a0a
Introduce a new API to create speculative connection with the partition key in originAttributes, r=necko-reviewers,valentin
https://hg.mozilla.org/integration/autoland/rev/3ee1184f75ef
Use origin attributes to start speculative connections for link header, r=necko-reviewers,timhuang,valentin
Status: NEW → RESOLVED
Closed: 11 months ago
Resolution: --- → FIXED
Target Milestone: --- → 115 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: