0

I'm using libev for watching FD events, but sometimes I need to close the underlying FD.

Therefore, I'm stopping the IO watcher (by calling its stop function), but it seems not enough, as I'm still getting this error after calling close(fd):

 ev_epoll.c:134: epoll_modify: Assertion `("libev: I/O watcher with invalid fd found in epoll_ctl", errno != EBADF && errno != ELOOP && errno != EINVAL)' failed.

How can I make sure to solve this error, if I don't want to delete the ev_loop as it still needs to watch other changes?

It seems, an IO-watcher added to ev_loop must always have to have a valid (opened) FD, even if it's stopped. Or am I doing something wrong?

myEVLoop = ev_loop_new(0);

myEVIO.stop();
myEVIO.set<MyClass, &MyClass::myRead>(this);
myEVIO.set(myEVLoop);

//... (some other ios and timers, and asyncs)

myEVIO.set(fd, ev::READ);
myEVIO.start();

IN THREAD1: ev_run(myEVLoop, 0);

IN THREAD2: myEVIO.stop(); close(fd);

After this close call the above error comes. Can I somehow conquer this?

Daniel
  • 2,318
  • 2
  • 22
  • 53

1 Answers1

1

Stopping all I/O watchers for an fd is enough. Either you close the fd before stopping the watcher, or you have more than one watcher for the same fd, or you are not really stopping the right watcher, or something completely different is happening, such as memory corruption.

The fact that you mention multiple threads, but no locking, makes the last (memory corruption) a likely candidate here. Does the problem go away without threads? If yes, then almost certainly you don't lock properly.

Remember Monica
  • 3,897
  • 1
  • 24
  • 31