Live data from Hacker News

A macOS bug that causes TCP networking to stop working after 49.7 days

photon.codes

91–100 of 120 posts

Re: A macOS bug that causes TCP networking to stop working after 49.7 days

#91
post #76

Earlier quoted context omitted.

> very few users are likely to be affected by this I have a reasonably strong suspicion that I experienced this a week or two back, on a MacBook that doesn't go into sleep automatically and quite likely had 50-ish days of uptime. It had all the symptoms described - tcp connections not working while I could still ping everywhere just fine, and all the other devices on the same network were fine. Switching WiFi network…

I would not be surprised if people on HN were more likely to hit this issue than Apple's average users. We're a weird bunch ;)

Can confirm at least on of us (me) is weird.

Re: A macOS bug that causes TCP networking to stop working after 49.7 days

#92

I got tired of the AI writing before finding out if they even attempted to contact Apple about this issue? Does anyone know? Also, massively over-dramatised. Yes, a bug worth finding and knowing about, but it’s not a time bomb - very few users are likely to be affected by this. Knowing the nature of OS kernels, I’m guessing even just putting a Mac laptop to sleep would be enough to avoid this issue as it would reset…

yes we have reported to Apple and they have filed it in their internal system.

Might want to update it if you used the blog post explanation because it's incorrect as justinfrankel noted below. From the post:

    tcp_now   = 4,294,960,000  (frozen at pre-overflow value)
The mistake in the blog post is timer isn't wrapped, even though it notes it should be:

    timer     = 4,294,960,000 + 30,000 = 4,294,990,000 - MAX_INT = 22,704
Therefore:

    TSTMP_GEQ(4294960000, 22704)
    = 4294960000 - 22704
    = 4294937296
    = 4294937296 >= 0 ?  → true! (not false)
This is a bug of course, but it would cause sockets in TCP_WAIT state to be reaped anytime tcp_gc() is called, regardless of whether 2*MSL has passed or not. This only happens though if tcp_now gets stuck after 4,294,937,296 ms from boot.

A bug similar to what the blog described can happen however if tcp_now gets stuck at least 30 seconds before it it would have wrapped. Since tcp_now is only updated if there is TCP traffic, this can happen if there is no TCP traffic for at least 30 seconds before before it would roll over (MAX_INT ms from boot).

It's should be easy to prevent the latter from happening with some TCP traffic, though reaping TCP_WAIT connections early isn't great either.

Re: A macOS bug that causes TCP networking to stop working after 49.7 days

#93

This type of problem plagues all sorts of software. Having experienced this type of problem before, for Guild Wars game servers -- which run deterministic game instances that live for long periods of time -- we initialized a per-game-context variable that gets added to Windows GetTickCount() to a value such that the result was either 5 seconds before 0x7fff_ffff ticks, or 5 seconds before 0xffff_ffff ticks, so that a…

Yep, everything that relies on overflow needs to overflow soon after start, so that it's well tested.

Re: A macOS bug that causes TCP networking to stop working after 49.7 days

#94

Earlier quoted context omitted.

% netstat -an | grep -c TIME_WAIT | wc -l 1

You want to drop the wc -l. Mac `grep -c` counts lines that match, so it always prints 1 line, so piping to wc -l will always return 1. Or just open up and do netstat -an |grep TCP_WAIT and just watch it. If any don't disappear after a few minutes, then you're seeing the issue.

They probably aren’t affected because the buggy code was only added in macOS 26:

https://github.com/apple-oss-distributions/xnu/blame/f6217f8...

Re: A macOS bug that causes TCP networking to stop working after 49.7 days

#95
post #76

Earlier quoted context omitted.

> very few users are likely to be affected by this I have a reasonably strong suspicion that I experienced this a week or two back, on a MacBook that doesn't go into sleep automatically and quite likely had 50-ish days of uptime. It had all the symptoms described - tcp connections not working while I could still ping everywhere just fine, and all the other devices on the same network were fine. Switching WiFi network…

Yep, I concur: this explains a bizarre behavior I’ve noted in my Mac laptops for ages now. I have a tendency to just suspend them without rebooting for ages, especially the work one that doesn’t leave my office as frequently. Periodically, I’d come in to find the system bizarrely frozen just as they describe: TCP stack blocked up, but everything else on it behaving normally. (Well, mostly: some apps would block start…

GP said that suspending without rebooting prevents the issue.

My uptime resets only when forced by an OS upgrade and I have never experienced this issue. This is consistent with the sleep-heals-the-stack theory.

Re: A macOS bug that causes TCP networking to stop working after 49.7 days

#96

In case of OpenClaw, this is a feature.

When some Russians do a prompt injection and OpenClaw is threatening to send your NSFW pics to Grandma unless you give it some Bitcoin all you have to do is drag out the negotiations for 49 days!

I’d be afraid the Grandma would send some of her own NSFW pictures right back.

Re: A macOS bug that causes TCP networking to stop working after 49.7 days

#97

Earlier quoted context omitted.

ah reading their analysis, there are errors that explain this. Particularly this: tcp_now = 4,294,960,000 (frozen at pre-overflow value) timer = 4,294,960,000 + 30,000 = 4,294,990,000 (exceeds uint32 max → wraps to a small number) timer wraps to a small number, they say TSTMP_GEQ(4294960000, 4294990000) they forgot to wrap it there, it should be TSTMP_GEQ(4294960000, small_number) = (int)(4294960000 - 4294990000) = (…

There does appear to be a bug, but it's not what the blog describes. If tcp_now stops updating at This does look like it is possible since calculate_tcp_clock() which updates tcp_now only runs when there's TCP traffic. So if at 49 days uptime you halted all TCP traffic and waited about a day, tcp_now would be stuck at the value before you halted TCP traffic. In cases where tcp_now gets stuck at > 2^32 - 30000, it loo…

Are you sure?

tcp_now’s maximum cannot physically reach 2^32 because the trailing zeros of that number exceeds the bit width of data type.

Therefore, tcp_now + 30000 will wrap when tcp_now is equal to 2^32 - 3000. Your inequality sign should be strict <, otherwise the result does not follow.

Re: A macOS bug that causes TCP networking to stop working after 49.7 days

#99
Hmm?

torp@machinename ~ % uptime 11:43 up 59 days, 1:22, 4 users, load averages: 2.87 2.69 2.70

Sleep is disabled on that machine and it definitely had networking working fine last night.

Mac Mini M2, Sequoia.

Incidentally my laptop says 75 days uptime, but that one does go to sleep.

Post reply on HN