[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] possible file descriptor leak



We've written a very simple client and server in Libevent.

When we start up the server and have the client make thousands of requests to the server, the client eventually ends with a "too many open files" error. (The system that ran this had the ulimit set to 4096.)

This only happens at the client and not the server. At the client side, lsof shows that the number of file descriptors actually increase over each request.

We tracked this problem down to evutil.c. In the function evutil_socket, we see this.


#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
r = socket(domain, type, protocol);
if (r < 0 && !(type & (SOCK_NONBLOCK|SOCK_CLOEXEC)))
return -1;
#endif
#define SOCKET_TYPE_MASK (~(EVUTIL_SOCK_NONBLOCK|EVUTIL_SOCK_CLOEXEC))
r = socket(domain, type & SOCKET_TYPE_MASK, protocol);


If the first call to socket() passes the error check, it is immediately overwritten by the next call to socket(). This results in a file descriptor leak.

This change was pretty recent (https://github.com/libevent/libevent/commit/a1c042bfe9238949a02a1050b9b4d3a1d36f5091).

Is this expected behavior?

Thanks,
Amarin