Linux - Networking This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-05-2004, 04:02 PM
|
#1
|
|
LQ Newbie
Registered: Oct 2003
Distribution: CentOS5
Posts: 20
Rep:
|
lsof can't identify protocol sock
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?
Thanks!
|
|
|
|
05-21-2004, 09:31 AM
|
#2
|
|
LQ Newbie
Registered: May 2004
Location: Riga, Latvia
Distribution: Gentoo, Slackware, mdk, rh
Posts: 2
Rep:
|
Hello.
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.
Karlo
|
|
|
|
05-21-2004, 11:42 AM
|
#3
|
|
LQ Newbie
Registered: Oct 2003
Distribution: CentOS5
Posts: 20
Original Poster
Rep:
|
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.
|
|
|
|
05-21-2004, 12:22 PM
|
#4
|
|
LQ Newbie
Registered: May 2004
Location: Riga, Latvia
Distribution: Gentoo, Slackware, mdk, rh
Posts: 2
Rep:
|
setrlimit()
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):
---[cut here]---
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/resource.h>
int main(int argc, char **argv) {
struct rlimit limit;
if (getrlimit(RLIMIT_NOFILE, &limit) == -1)
printf("getrlimit(): %s (errno=%d)\n", strerror(errno), errno);
else {
printf("Old limits for RLIMIT_NOFILE: rlim_cur=%d rlim_max=%d\n",
limit.rlim_cur, limit.rlim_max);
limit.rlim_cur = limit.rlim_max = 65535;
if (setrlimit(RLIMIT_NOFILE, &limit) == -1)
printf("setrlimit(): %s (errno=%d)\n", strerror(errno), errno);
else {
if (getrlimit(RLIMIT_NOFILE, &limit) == 0)
printf("New limits for RLIMIT_NOFILE: rlim_cur=%d rlim_max=%d\n",
limit.rlim_cur, limit.rlim_max);
else
printf("getrlimit(): %s (errno=%d)\n", strerror(errno), errno);
}
}
/* Process with your socket fd stuff here...
*/
return 0;
}
---[cut here]---
Wbr,
Karl Tiller
Last edited by Karlo; 05-21-2004 at 12:26 PM.
|
|
|
|
05-21-2004, 12:34 PM
|
#5
|
|
LQ Newbie
Registered: Oct 2003
Distribution: CentOS5
Posts: 20
Original Poster
Rep:
|
Oh OK, Thanks for that work-around idea!
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:22 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|