And curl says "Can't assign requested address"
There's a few threads and discussions around without proper solutions, so figured (sorry 😄) I'll add my case & findings here for future reference.
The scenario:
- User realises that web browser is starting to throw more and more errors during use, up to the point when no website loads anymore.
- Other network services are also choppy, but ping and traceroute looks all ok.
- Running a curl -v https://www.google.com in the terminal results in a "Can't assign requested address" message.
I usually reboot my computer as I can't search for solutions, and I'm OK for almost a week, but have to do it often.
In my case, a "small number" of iPhone / iPad connections (over 16000), eat up all the available sockets. Running net stat takes about 2 minutes to produce all the results, showing a significant number of connections in CLOSE_WAIT from those devices (host names or IP addresses).
You can either send ACK with using something like https://github.com/rghose/kill-close-wait-connections, but being as impatient as we are, you may just kill all of them.
See what's in:
netstat -v |grep 'CLOSE_WAIT'
This gives you a list of all CLOSE_WAIT connections, so you may want to keep limiting this list to avoid "overkilling", e.g. in my network, I've got all devices called "iPhone" or "iPad" that cause this problem.
So this does the trick for me:
netstat -v |grp "CLOSE_WAIT" | grep -i "iphone\|ipad" |awk '{print $9}' |sort |uniq | xargs kill
Consider this as kill to live another day, not more.
Hope this helps some folks before they throw their Macs into the Sun.
mb