Skip to content

Commit e04cde4

Browse files
KershawChangkjang@mozilla.com
authored andcommitted
Bug 1990699 - Allow fallback to coalescing connection, r=necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D267200
1 parent f8266ef commit e04cde4

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

netwerk/protocol/http/nsHttpConnectionMgr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3453,6 +3453,9 @@ ConnectionEntry* nsHttpConnectionMgr::GetOrCreateConnectionEntry(
34533453
("GetOrCreateConnectionEntry is coalescing h2/3 an/onymous "
34543454
"connections, ent=%p",
34553455
invertedEnt));
3456+
if (aAvailableForDispatchNow) {
3457+
*aAvailableForDispatchNow = true;
3458+
}
34563459
return invertedEnt;
34573460
}
34583461
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
"use strict";
6+
7+
/* import-globals-from head_http3.js */
8+
9+
const { NodeHTTP2Server } = ChromeUtils.importESModule(
10+
"resource://testing-common/NodeServer.sys.mjs"
11+
);
12+
13+
function makeChan(uri) {
14+
let chan = NetUtil.newChannel({
15+
uri,
16+
loadUsingSystemPrincipal: true,
17+
}).QueryInterface(Ci.nsIHttpChannel);
18+
chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
19+
return chan;
20+
}
21+
22+
function channelOpenPromise(chan, flags) {
23+
return new Promise(resolve => {
24+
function finish(req, buffer) {
25+
resolve([req, buffer]);
26+
}
27+
chan.asyncOpen(new ChannelListener(finish, null, flags));
28+
});
29+
}
30+
31+
add_setup(async function setup() {
32+
Services.prefs.setCharPref("network.dns.localDomains", "alt1.example.com");
33+
34+
let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
35+
Ci.nsIX509CertDB
36+
);
37+
addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
38+
addCertFromFile(certdb, "proxy-ca.pem", "CTu,u,u");
39+
40+
// A dummy request to make sure AltSvcCache::mStorage is ready.
41+
let chan = makeChan(`https://localhost`);
42+
await channelOpenPromise(chan, CL_EXPECT_FAILURE);
43+
});
44+
45+
add_task(async function test_fallback() {
46+
// We only need the `noResponsePort`, not the masque proxy.
47+
const { noResponsePort } = await create_masque_proxy_server();
48+
49+
Services.prefs.setCharPref(
50+
"network.http.http3.alt-svc-mapping-for-testing",
51+
`alt1.example.com;h3=:${noResponsePort}`
52+
);
53+
54+
let server = new NodeHTTP2Server();
55+
await server.start(noResponsePort);
56+
57+
Assert.equal(server.port(), noResponsePort);
58+
59+
await server.registerPathHandler("/request1", (req, resp) => {
60+
resp.writeHead(200);
61+
resp.end("response1");
62+
});
63+
await server.registerPathHandler("/request2", (req, resp) => {
64+
resp.writeHead(200);
65+
resp.end("response2");
66+
});
67+
68+
registerCleanupFunction(async () => {
69+
await server.stop();
70+
});
71+
72+
let chan = makeChan(
73+
`${server.protocol()}://alt1.example.com:${server.port()}/request1`
74+
);
75+
let [req, buf] = await channelOpenPromise(
76+
chan,
77+
CL_IGNORE_CL | CL_ALLOW_UNKNOWN_CL
78+
);
79+
Assert.equal(req.protocolVersion, "h2");
80+
Assert.equal(buf, "response1");
81+
82+
let chan1 = makeChan(
83+
`${server.protocol()}://alt1.example.com:${server.port()}/request2`
84+
);
85+
chan1.loadFlags = Ci.nsIRequest.LOAD_ANONYMOUS;
86+
[req, buf] = await Promise.race([
87+
channelOpenPromise(chan1, CL_IGNORE_CL | CL_ALLOW_UNKNOWN_CL),
88+
// chan1 should be completed within a short time.
89+
new Promise(resolve => {
90+
do_timeout(3000, resolve);
91+
}),
92+
]);
93+
Assert.equal(req.protocolVersion, "h2");
94+
Assert.equal(buf, "response2");
95+
96+
await server.stop();
97+
});

netwerk/test/unit/xpcshell.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,13 @@ skip-if = [
788788
run-sequentially = ["true"] # node server exceptions dont replay well
789789
skip-if = ["os == 'win' && os_version == '11.26100' && processor == 'x86_64' && msix"] # Bug 1807931
790790

791+
["test_http3_fallback_anonymous_conn.js"]
792+
run-sequentially = ["true"] # node server exceptions dont replay well
793+
skip-if = [
794+
"os == 'android'",
795+
"os == 'win' && os_version == '11.26100' && processor == 'x86_64' && msix'", # Bug 1808049
796+
]
797+
791798
["test_http3_fast_fallback.js"]
792799
run-sequentially = ["true"] # node server exceptions dont replay well
793800
skip-if = [

0 commit comments

Comments
 (0)