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

[Libevent-users] event_add fails with ENOENT when on epoll



Hi,

I've run into an issue where event_add() fails with ENOENT.
This happens when a socket reuses a descriptor that was recently
closed and was used before with another event.

The details are below. The question I have is - what are the ways to
work around this?

Thanks,
Denis.
http://www.gevent.org - Python network library based on libevent.

---

Here's how to reproduce the bug:

#include "event.h"
#include <stdio.h>
#include <sys/socket.h>

int main()
{
    struct event server_event, client_event;
    int server_socket, client_socket;

    printf("%s\n", event_get_version());
    event_init();

    server_socket = socket(AF_INET, SOCK_STREAM, 0);
    printf("server_socket=%d\n", server_socket);
    event_set(&server_event, server_socket, EV_READ, NULL, NULL);
    if (event_add(&server_event, NULL))
        perror("event_add(server_event)");

    close(server_socket);

    client_socket = socket(AF_INET, SOCK_STREAM, 0);
    printf("client_socket=%d\n", client_socket);
    event_set(&client_event, client_socket, EV_READ, NULL, NULL);
    if (event_add(&client_event, NULL))
        perror("event_add(client_event)");
}


And here's the output:

libevent-test-errno2$ ./test_errno2 # libevent-1.4.13 with epoll backend - fails
1.4.13-stable
server_socket=6
client_socket=6
event_add(client_event): No such file or directory

relevant strace:

epoll_create(32000)                     = 3
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 6
epoll_ctl(3, EPOLL_CTL_ADD, 6, {EPOLLIN, {u32=6, u64=6}}) = 0
close(6)                                = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 6
epoll_ctl(3, EPOLL_CTL_MOD, 6, {EPOLLIN, {u32=6, u64=6}}) = -1 ENOENT
(No such file or directory)


libevent-test-errno2$ EVENT_NOEPOLL=1 ./test_errno2 # libevent-1.4.11
with poll backend - OK
1.4.11-stable
server_socket=5
client_socket=5


libevent-test-errno2$ ./test_errno2_2 # libevent-2.0.4-alpha with
epoll backend - OK
2.0.4-alpha
server_socket=8
client_socket=8
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.