Problem Summary

The message of "too many open files" indicates that a process isn't closing file descriptors properly. In Unix, everything is a file, and every user (including system users) has a limit on what system resources it is allowed to consume. If they exceed that limit, the system won't allow them to do more. It keeps runaway processes from consuming 100% of the system resources, and it's usually a good thing.





In this case it's usbmuxd that's the bad player. You will find system.log filled with errors related to "too many open files," and if you use "lsof" to inspect the process, you'll find that it has thousands upon thousands of IPv4 and IPv6 TCP connections left in CLOSE_WAIT state. You can also see this with netstat, which doesn't require sudo. In my case they're all connections to port 62078. Some are to my iPhone. I suspect that the others are the various other iPhones and iPads that my wife and I have around the house. CLOSE_WAIT is a TCP state where the server (my MBP) has received the first FIN packet from the client (my phone). The OS is now waiting for the application (usbmuxd) to execute a close() call on the socket. usbmuxd isn't doing so, thus the sockets pile up until the MBP is out of resources to give to usbmuxd. This results in the lockdownd errors and everything else.





[monachus@poison ~]$ netstat -an | grep 62078 | head tcp6 0 0 fe80::426c:8fff:.54684 fe80::1074:8059:.62078 CLOSE_WAIT tcp6 0 0 fe80::426c:8fff:.54674 fe80::1408:c1f2:.62078 CLOSE_WAIT tcp6 0 0 fe80::426c:8fff:.54669 fe80::1408:c1f2:.62078 CLOSE_WAIT tcp6 0 0 fe80::426c:8fff:.54661 fe80::1408:c1f2:.62078 CLOSE_WAIT tcp4 0 0 10.68.0.14.54660 10.68.1.7.62078 CLOSE_WAIT tcp6 0 0 fe80::3e15:c2ff:.54659 fe80::1408:c1f2:.62078 CLOSE_WAIT tcp4 0 0 10.68.0.14.54658 10.68.1.7.62078 CLOSE_WAIT tcp6 0 0 fe80::426c:8fff:.54657 fe80::1408:c1f2:.62078 CLOSE_WAIT tcp4 0 0 10.68.0.14.54500 10.68.1.7.62078 CLOSE_WAIT tcp6 0 0 fe80::3e15:c2ff:.54499 fe80::1408:c1f2:.62078 CLOSE_WAIT [monachus@poison ~]$ netstat -an | grep 62078 | wc -l 4842







The source of the problem is that usbmuxd is not closing sockets. 4800 sockets in CLOSE_WAIT state! Thanks, dude. This is so totally amateur that Apple should be ashamed, but let's remember that they don't read these forums, and they don't care. They're working on the Next Big Screen or something else designed to strip us of our money. We bought in. This is our fault.





The Solution

usbmuxd is a system process that is controlled by launchd, which means that if you punch it in the face, it'll restart. This frees the (old) usbmuxd locks on the sockets, and the OS will begin to close them. You can find the PID of usbmuxd using "ps" and then use "sudo kill" to terminate the process.





[monachus@poison ~]$ ps ax | grep usbmuxd 42 ?? Ss 0:00.32 /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/Resources/u sbmuxd -launchd [monachus@poison ~]$ sudo kill 42 Password: [monachus@poison ~]$ ps ax | grep usbmuxd 25528 ?? Ss 0:00.03 /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/Resources/u sbmuxd -launchd [monachus@poison ~]$ netstat -an | grep 62078 | wc -l 4465 [monachus@poison ~]$ netstat -an | grep 62078 | wc -l 4463 [monachus@poison ~]$ netstat -an | grep 62078 | wc -l 4457 [monachus@poison ~]$ netstat -an | grep 62078 | wc -l 4457 [monachus@poison ~]$ netstat -an | grep 62078 | wc -l 4372 [monachus@poison ~]$ netstat -an | grep 62078 | wc -l 4357 [monachus@poison ~]$ netstat -an | grep 62078 | wc -l 4298







At this point your devices can be reconnected, and they'll work...for a while. The next time you get the "Trust This Computer?" loop, punch usbmuxd in the face again.





I checked back through the logfiles, and it seems that it takes about 34 hours for usbmuxd to suck up its maximum quota of resources. Since kicking it harms nothing, you can set up a cron job to do this automatically, and at least then we can avoid the fist-shaking rage of having to tolerate incompetence. I've put the following line into root's crontab to run every 24 hours, before I get up in the morning:





14 4 * * * ps ax | grep usbmuxd | grep -v grep | awk '{ print $1 }' | xargs kill







If you know how to put something into root's crontab, then you'll be fine with this. If you don't know what I'm talking about, then you shouldn't be playing around with this stuff. Instead, you'll have to shake your fist and wait for Apple to wake up and fix their s***.





Happy Wednesday.





Adrian