Hang in fd_ebadf function

Marc Lehmann schmorp at schmorp.de
Tue Jun 3 05:37:53 CEST 2008


On Mon, Jun 02, 2008 at 11:31:22PM -0400, Marc-André Cournoyer <macournoyer at gmail.com> wrote:
> What I'm doing is: if the EV_ERROR bit is set, close the connection  
> right away.

Which connection? EV_ERROR means the connection doesn't exist, so whatever
you close, likely is something else, another bug.

> I'm also closing the connection if there's any error send- ing or
> recv-ing on a socket.

Thats fine - you would not have to handle EV_ERROR if you did that (and
are single-threaded), as send/recv gives you the same error.

> By "it works" I meant that it stoped hanging when there was an error  
> on the socket before the send or recv.

Yes, but your program is still buggy. What you did is trade a certain bug
against a bug that occurs more rarely.

Getting EV_ERROR is (in your case) a programming bug in your code, not something you
can work around by closing some unrelated fd - it means you register a
watcher on a fd that you cnanot register a watcher on, likely some that
doesn't have any conenction.

I mean, I could care less about your code, but not fixing the bug and relying
on libev detecting the condition for you and hoping all is well asks for
disaster.

It is *much* better to fix your code instead.

> Let me know if you think I'm doing something wrong.

You are fighting the symptoms, you are not fixing the bug. EV_ERROR means
your code has a big bug somewhere. libev doesn't catch this bug with all
backends, not can it work efficiently in the presense of such a bug.

> But I know there is still something weird in there when using Ruby  
> threads, I'm trying to figure it out.

If you are using threads, then all bets are off - libev cannot reliably
detect this bug when threads are in use, and closing an fd that is already
closed (the most likely cause for your EV_ERROR) means you *will* close an
unrelated fd if some other thread created a new fd.

This is an extremely big bug in your code. libev cannot reliably detect
it, and you cannot work around it afterwards, you have to avoid it in the
first place.

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      pcg at goof.com
      -=====/_/_//_/\_,_/ /_/\_\



More information about the libev mailing list