libev application stops responding and consumes 100% cpu

Marc Lehmann schmorp at schmorp.de
Tue Apr 8 23:46:46 CEST 2014


On Tue, Apr 08, 2014 at 12:40:41AM -0700, Kirill Timofeev <kvt at hulu.com> wrote:
> Hi Marc,
> 
> yes, I was using this url as starting point: http://codefundas.blogspot.com/2010/09/create-tcp-echo-server-using-libev.html

yeah, the infinite loop in there is pointless, ev_run/ev_loop does not
return if there is work to do or ev_break is used. in the example,
however, it's likely harmless, as ev_loop never returns in practice.

> Could you please point me to code example or documentation regarding
> current best practice for keeping event loop running forever?

the current best practise is to let it run forever.

having the while loop will only hide bugs and will never be useful. it
should be dropped without any hesitation.

playing around with ev_ref would be counter-productive, because it would
also just hide the actual bug and probably cause worse issues later on.

> those timers are never removed from event loop.

then ev_run/ev_loop will not return either.

also, have you actually verified that ev_loop actually returns or not? you
are not really giving us enough information to work with - we still do not
know what is actually happening and you keep us guessing here. you need to
start *debugging* your program - use printf if must be :)

for example, the 100% could be caused by a timer that keeps firing and is
never reset, or an I/O watcher for a socket that signals read readyness
but you never read from it and so on. in both cases you'd see 100%, with
or without the while loop.

> Is it expected, that watchers would be dropped from event loop?

only if you explicitly stop them or have some bugs (such as memory
corruption).

> Would it be good idea to move timer initialization/start calls in the
> while loop as well?

the only effect that the while loop has is to hide bugs in your code. if
you think you have active watchers and ev_loop returns, then you should
debug your program and see if you corrupt watcher structures somewhere
(such as freeing them while in use, or corrupting their contents, which is
surprisingly common).

you can recompile libev with -DEV_VERIFY=3 and assertions switched on -
this can slow down your program a lot but will often catch such errors
early.

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



More information about the libev mailing list