libev application stops responding and consumes 100% cpu
kvt at hulu.com
Wed Apr 9 20:25:56 CEST 2014
I switched to 4.15, which has assertions compiled in and it appeared,
that I'm registering certain callback with certain watcher while
previous callback with same watcher was not completed and not removed
from event loop. I added check for this and so far everything works ok,
thank you very much for your help and great library.
On 04/08/2014 04:24 PM, Kirill Timofeev wrote:
> Thanks a lot for your comments Marc, I'll try to debug my code more,
> would ask list again if I'll meet any serious difficulties.
> On 04/08/2014 02:46 PM, Marc Lehmann wrote:
>> 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:
>> 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
>>> 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
More information about the libev