libev: segmentation fault in ev_feed_event().

Marc Lehmann schmorp at schmorp.de
Fri Sep 8 21:39:43 CEST 2023


On Fri, Sep 08, 2023 at 02:32:46PM -0400, Olivier Langlois <olivier at trillion01.com> wrote:
> but beside that, I have a hard time figuring out what could cause a
> segv into that small function...

Almost always, this is caused by race condiitons between threads. For
example, starting or stopping watcheres from multiple threads without
locking the loop.

> As a side note, I think that the assert text should be:
> "libev: pipe_w not active, but pipe written"

We don't know if the pipe was written. What we do know is that the intent
was that the pipe was not written, so the officially, the pipe was not
written, but the watcher  is also not active.

> An exceptional occurence but theoritically possible is the following:
> 
> ev_async_send() is called by another thread while the loop thread is
> processing pending watchers and one of these watchers is calling
> ev_async_stop() on the pending async watcher...

While its probably a (semantic) bug to do so, it is harmless to call
ev_async_send on a stopped watcher (other than losing the event, or
getting a spurious event later). Stopping and freeing the watcher would be
a different story, of course.

> I am currently studying libev code to convince myself that libev code
> handle correctly this case...

The more eyes, the better.

-- 
                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