Finding · macOS · Networking · TCP
macOS resends the SYN too early after it caches a too-steady round trip, and Telegram resets the connection
macOS caches TCP timing for each destination and starts new connections from it. A bot's long poll taught a Mac a 99 ms round trip with only 1 ms of variation, so new connections to Telegram resent their SYN at about 103 ms, just before the real 107 ms reply. Telegram's load balancer answered the duplicate too, and the connection was later reset. About 5% of new HTTPS requests to the Bot API failed.
Ryan McMillan · Found Sep 29, 2026 · Published Nov 28, 2026
Affected
- OS
- macOS 27.0 (Mac mini); the setting is unchanged on 27.2.1
- Setting
- net.inet.tcp.init_rtt_from_cache = 1 (the default; read-only in release builds)
- Destination
- Telegram Bot API, 149.154.160.0/20
- Trigger
- A long-lived, steady connection to the same server, such as a bot's long poll
- Admin rights
- Not needed to check; needed for the fix
01
What happens
macOS stores TCP timing on the route to each destination: round-trip time, its variation and the slow-start threshold. With net.inet.tcp.init_rtt_from_cache on, a new connection to that destination starts from the stored values instead of the conservative defaults. That includes how long it waits before sending its first SYN again.
A Telegram bot keeps a long-poll connection to the Bot API open all day. That steady traffic taught the Mac a round trip of 99 ms with a variation of 1 ms. XNU sets the first retransmit timeout to the round trip plus four times its variation, so new connections waited 99 + 4 = 103 ms. The real round trip from here was about 107 ms, so the SYN went out a second time just before the first reply arrived.
Telegram's load balancer answered both SYNs, most likely from two different servers. The Mac completed the handshake with the first answer, and the connection was later reset from Telegram's side. About 5% of new HTTPS requests failed this way. Another Mac on the same macOS version, network and public IP had no cached entry and no failures.
The setting can't be turned off: it is read-only in Apple's release builds. Deleting the cached entry works, but not for long. The Mac learned almost the same values again within 16 minutes.
02
Evidence
Diagnosed on September 29, 2026 with packet captures at the network edge, while request loops ran on the affected Mac and on other machines at the same time. The cached entry and the locked setting:
$ route -n get 149.154.166.110 | grep -A1 recvpipe
recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
0 0 33866070 99 1 0 1500 0
$ sysctl net.inet.tcp.init_rtt_from_cache
net.inet.tcp.init_rtt_from_cache: 1
$ sudo sysctl -w net.inet.tcp.init_rtt_from_cache=0
sysctl: oid 'net.inet.tcp.init_rtt_from_cache' is read only- Capture: the affected connections sent the same SYN twice, about 102 ms apart, with the same sequence number. The two answers had different sequence numbers and TTLs, which points to two servers. The resets came from Telegram's side; the network in between only forwarded them.
- Before: 13 of 24 connection attempts sent the SYN twice, and 7 to 15 requests failed every five minutes.
- Cached entry deleted: 100 of 100 connection attempts sent one SYN, and 204 of 204 requests succeeded. Within 16 minutes the cache was back at 97 ms with 1 ms of variation.
- Timing locked (fix below): 221 of 221 connection attempts sent one SYN, and 222 of 222 requests succeeded.
- Controls: another Mac on the same macOS version and public IP had no cached entry and 0 of 185 requests failed. Requests from the affected Mac to GitHub and Cloudflare never failed.
- Source: in Apple's published XNU source,
tcp_getrt_rtt()seeds a new connection from the route's cached values whentcp_init_rtt_from_cacheis set, andtcp_rto_formula()gives a first timeout of round trip plus four times variation. The sysctl is writable only in development builds. - Durability: two months later the lock still holds, survived a reboot (the boot-time job re-applied it), and is still needed on macOS 27.2.1, where the setting is still on.
03
Reproduce
- 01On a Mac that keeps a long-lived connection to a server (a Telegram bot's long poll is enough), run
route -n get <server-ip> | grep -A1 recvpipe. A non-zerortt,msecwith anrttvarof 1 or 2 means new connections will start from that estimate. - 02Work out the first retransmit timeout:
rtt + 4 × rttvar. Then measure the real round trip, for examplecurl -so /dev/null -w '%{time_connect}\n' https://api.telegram.orga few times. Trouble starts when the timeout is just below the real round trip. - 03Capture new connections with
sudo tcpdump -ni en0 'tcp[tcpflags] & tcp-syn != 0 and host <server-ip>'. Two SYNs with the same sequence number, about one timeout apart, are the bug. - 04Loop requests and count failures, then delete the cached entry (
sudo route -n delete <server-ip>, plus-ifscope en0for a scoped entry) and count again.
04
Fix and cautions
Add a route for the destination's address range through your normal gateway, with the timing values locked above the real round trip. macOS doesn't overwrite locked values, and XNU treats a locked round trip as the minimum retransmit timeout, so new connections wait long enough before sending the SYN again. The traffic takes the same path. Values are in microseconds; replace en0 with your interface.
GW=$(route -n get default | awk '/gateway/{print $2}')
sudo route -n add -net 149.154.160.0/20 "$GW" -lockrest -rtt 150000 -rttvar 50000
sudo route -n add -net 149.154.160.0/20 "$GW" -ifscope en0 -lockrest -rtt 150000 -rttvar 50000
sudo route -n delete -ifscope en0 149.154.166.110 # drop the stale cached entry
route -n get 149.154.166.110 | grep -A1 recvpipe # expect 150L 50L (L = locked)Routes added this way don't survive a reboot or a change of gateway. I re-apply them from a root LaunchDaemon that runs at boot and every five minutes and only acts when the lock is missing. To undo, delete both routes: sudo route -n delete -net 149.154.160.0/20, then the same command with -ifscope en0.
05
Not tested
- Seen on one Mac mini, against Telegram's Bot API. I haven't seen it with other services, though any server behind a load balancer that answers a duplicate SYN separately could react the same way.
- Found on macOS 27.0. The setting is still on and the lock still needed on 27.2.1, but I haven't removed the lock there to re-measure the failure rate.
- Apple's newest published XNU source may be older than macOS 27, so the code path is confirmed in source and matches the measurements, but isn't proven for 27 itself.
- That the two answers came from two different servers is inferred from their sequence numbers and TTLs, not seen directly.
- Telegram publishes several address ranges. I only locked 149.154.160.0/20, the range my bot uses.
- The same captures showed a separate burst of retransmitted FIN packets after connections closed. It didn't cause the resets, and I haven't explained it.
06
Prior work checked
- XNU source: tcp_getrt_rtt() in bsd/netinet/tcp_subr.cWhere macOS seeds a new connection's timing from the route cache, and where a locked round trip becomes the minimum retransmit timeout.
- Linux: tcp: do not use cached RTT for RTT estimationA 2013 Linux change that stopped seeding the RTT estimator from cached values and uses them only to set the first timeout conservatively. A related design choice, not the same bug. I found nothing for macOS.
- telegram-bot-api #896: backends reset ClientHellos that offer X25519MLKEM768Resets from the same Telegram address with a different cause: some backends reject post-quantum key exchange in the TLS handshake.
- telegram-bot-api #906: intermittent TCP RST on established TLS connectionsResets from the same address, opened the same day, on connections that were already established and from Linux. A different pattern from duplicate SYNs on new connections.
- Telegram's published address rangesThe ranges to lock if your bot uses others.
Know of earlier write-ups? Tell me and I'll credit them here.
Updates
- Nov 28, 2026Published.