naive inbound (HTTP/3): no QUIC keep-alive, idle connections close after ~30s and the next request pays a new handshake
Operating system
Linux
System version
Ubuntu 26.04 (Linux 7.0, arm64)
Installation type
Original sing-box Command Line
If you are using a graphical client, please provide the version of the client.
No response
Version
sing-box version 1.14.2
Environment: go1.26.8 linux/arm64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale,with_ccm,with_ocm,with_cloudflared,with_naive_outbound,with_usbip,with_openvpn,with_openconnect,badlinkname,tfogo_checklinkname0,with_purego
Revision: af6e64c3b69e6132ebaee0e1a3d24e93903f6709
CGO: disabledDescription
The HTTP/3 listener of the naive inbound builds its quic.Config with fixed values and no keep-alive:
quicListener, err := qtls.ListenEarly(udpConn, tlsConfig, &quic.Config{
MaxIncomingStreams: 1 << 60,
Allow0RTT: true,
DisablePathManager: true,
})The client side (Cronet, used by the naive outbound) does not keep an idle connection alive either. So a naive-over-QUIC connection that has been idle for about 30 seconds is closed, and the next request pays a full QUIC handshake again. On a 160 ms RTT link, the first request after 65 s or 200 s of idle takes 2 RTT instead of 1 RTT. Over naive with HTTP/2 the same test stays at 1 RTT.
Unlike the tuic and hysteria2 inbounds, NaiveInboundOptions does not embed QUICOptions, so this can't be configured (keep_alive_period / idle_timeout are rejected as unknown fields). The listener code is the same on v1.15.0-alpha.9 and the testing branch.
As an experiment I built v1.14.2 with only this one-line change, and it removes the reconnect. Apparently Cronet resets its idle timer when packets arrive from the server, so a server-side keep-alive keeps the connection up without any client change:
MaxIncomingStreams: 1 << 60,
Allow0RTT: true,
DisablePathManager: true,
+ KeepAlivePeriod: 10 * time.Second,
})Proposal: embed QUICOptions in NaiveInboundOptions, as the tuic and hysteria2 inbounds already do. Then pass at least keep_alive_period and idle_timeout to the HTTP/3 listener's quic.Config. A non-zero default keep-alive would also work if you prefer not to add options.
Reproduction
All local, loopback only. Generate a certificate with the default 1-month validity. Cronet rejects longer self-signed certificates with cert validity too long, and a 12-month one already failed.
sing-box generate tls-keypair example.org
# save the PRIVATE KEY block as key.pem and the CERTIFICATE block as cert.pemserver.json:
{
"log": { "level": "warn" },
"inbounds": [
{
"type": "naive",
"listen": "127.0.0.1",
"listen_port": 10000,
"users": [{ "username": "sekai", "password": "password" }],
"tls": {
"enabled": true,
"server_name": "example.org",
"certificate_path": "cert.pem",
"key_path": "key.pem"
}
}
]
}client.json:
{
"log": { "level": "warn" },
"inbounds": [{ "type": "mixed", "listen": "127.0.0.1", "listen_port": 10001 }],
"outbounds": [
{
"type": "naive",
"server": "example.org",
"server_port": 10000,
"username": "sekai",
"password": "password",
"quic": true,
"tls": {
"enabled": true,
"server_name": "example.org",
"certificate_path": "cert.pem"
}
}
],
"dns": {
"servers": [
{ "type": "hosts", "tag": "hosts", "predefined": { "example.org": "127.0.0.1" } }
]
}
}Steps:
python3 -m http.server 10002 --bind 127.0.0.1 &
sing-box run -c server.json &
sing-box run -c client.json &
curl -x socks5h://127.0.0.1:10001 http://127.0.0.1:10002/ # request 1
# count QUIC long-header (handshake) packets from now on
tcpdump -i lo -nn 'udp port 10000 and (udp[8] & 0x80 != 0)' &
sleep 40
curl -x socks5h://127.0.0.1:10001 http://127.0.0.1:10002/ # request 2Result (both requests return 200, run twice each):
| Server | Long-header packets during request 2 |
|---|---|
| official 1.14.2 | 7 (a new handshake) |
1.14.2 + KeepAlivePeriod: 10s |
0 (connection reused) |
The same comparison through netns with 160 ms of emulated RTT: first request after 65 s / 200 s of idle takes 2.0 RTT with the official server and 1.0 RTT with the patched one.
Logs
Nothing relevant at warn level on either side: the idle connection closes silently and the client opens a new QUIC connection for request 2.Supporter
- I am a sponsor
Integrity requirements
- I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
- I confirm that I have provided the server and client configuration files and process that can be reproduced locally, instead of a complicated client configuration file that has been stripped of sensitive data.
- I confirm that I have provided the simplest configuration that can be used to reproduce the error I reported, instead of depending on remote servers, TUN, graphical interface clients, or other closed-source software.
Source: SagerNet/sing-box