Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm trying to debug a program using lsof. I've been seeing a file-descriptor leak in /proc/$PID/fd from sockets that eventually keeps me from being able to create new network connections when I hit the resource limit.
lsof shows me that the socket handles that are being leaked are identified with "TYPE=sock 0,0 ...can't identify protocol" I've performed an strace and there are never any calls made (network or otherwise) that return the file-descriptors that match the bad ones in lsof.
My question is, where are these "sock" type sockets being created? Does anyone else know where they come from and how to get rid of them?
Are you running out of socket file descriptors? Check function names getrlimit and setrlimit, their prototypes can be found in file /usr/include/sys/resource.h. This should help.
Yes, as I stated, I am running out of fd resources. I can see that using lsof and from /proc/$PID/fd. I believe my program sets itself a limit of 1024 file-descriptors, which it should never use more than 50 of, even when very busy. In fact, I can account for all socket opens and closes in the app and do not otherwise leak socket handles.
These sock-type sockets appear as if from no where...I have not been able to track their origin using strace, meaning no system call I can see returns values equal to the socket handle. If anyone has seen these types show up in lsof and knows why they may be created I would appreciate your knowledge.
FYI, One user of handles I could not account for is openlog and syslog since they do not return their handle IDs. I tried commenting them out of the code and it had no affect.
I faced with the same problem. The fd limit per process is 1024 by default. And the lsof output contained the same thing.
The solution to not run out of fds there was to change that system resource max number of open files (fds) per current process limit to, e. g. 65535. Try it.
Like (program is written right here, may contain syntactic errors):
The one reservation I have is that this is not a safe thing to do for an app expected to run on a production system. Ultimately, I would rather fix the leak than just give it a bigger bucket to spill into. I'll give your idea a try and then test to see what happens when I reach RLIM_INFINITY.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.