YouTube Summaries

← All summaries

Mac is running out of time

2026-05-06 Wed ⏱ 10 min @ThePrimeagen

Photon discovered macOS bricks its TCP stack after exactly 49 days, 17 hours, 2 minutes, 47 seconds of uptime — a uint32 millisecond overflow in calculate_tcp_clock that freezes TIME_WAIT and exhausts ephemeral ports.

Setup

  • Heisenbugs: bugs that vanish when you instrument them = timing bugs.
  • TCP TIME_WAIT (RFC 793): a closed port must wait ~30 s before reuse so stray packets can't poison new connections.
  • Integer overflow: 4.2B ms ≈ 49 d 17 h 2 min 47 s.

The bug

  • xnu/bsd/netinet/tcp_subr.c::calculate_tcp_clock multiplies uptime seconds by 1000 and casts to uint32. After ~49 days it wraps to near-zero.
  • The shared TCP "now" only advances when temp < now — but after wrap, now is tiny, so the global clock freezes.
  • Frozen clock means TIME_WAIT never expires → ports never freed → ~32k connections in and the machine can't open new TCP sockets at all. Existing connections still work.
  • Same shape as Y2K38, just shorter horizon. Saving 4 bytes by not using uint64 cost everyone running long-lived Macs.