Today's Monday call is, at best guess, some obscure change in some Vodafone Global IoT routing whatever. The effect is that the connections of the thousands of devices that report via long polling to one of our machines, are not closing, and the server process runs out of file descriptors.
We aren't able to touch the code of that service anymore (eventually we'll hopefully rewrite it), plan B was to forcefully close the connections that have been idle for too much.
After some research, it turned out that it is indeed possible to do that and so here's closesocks:
$ closesocks --help usage: closesocks [-h] [--verbose] [--debug] [--pid pid] [--idle seconds] [--force] List idle open sockets, and optionally close them optional arguments: -h, --help show this help message and exit --verbose, -v verbose output --debug debug output --pid pid, -p pid pid to list --idle seconds select connections idle for more than this amount of seconds (default: 3600) --force, -f run the commands instead of listing them
It is a quick and simple script to list idle open sockets for a process, and optionally close them.
It generates ss command lines to kill the processes. By default it shows them, and can also directly run them.