ev_stat inotify implementation might miss events

Yoann Vandoorselaere yoann.v at prelude-ids.com
Mon Jan 25 20:46:37 CET 2010


Le lundi 25 janvier 2010 à 19:39 +0100, Marc Lehmann a écrit :
> On Mon, Jan 25, 2010 at 04:13:50PM +0100, Yoann Vandoorselaere <yoann.v at prelude-ids.com> wrote:
> > The ev_stat inotify backend can miss files events while the ev_stat
> > notification callback execute. If additional changes occurs before the
> > main libev loop resume, the events will be lost.
> 
> Could you explain this in more detail? What events did you get, what did
> you expect instead?

Using a simple script that perform the following:

#!/bin/bash
echo "testcase" >> monitored_file
echo "testcase" >> monitored_file
echo "testcase" >> monitored_file
echo "testcase" >> monitored_file

Every write will trigger a libev events *if* the libev specified
callback function return sufficiently fast. 

But if you introduce enough delay in the callback function, then every
write that has happened while the callback function was running (more
specifically before stat_timer_cb:ev_stat_stat() is called) will be
missed.

I suspect that this happen because ev_stat_stat() update the ev_stat
stored stat information, misleading libev to "thinking" everything up to
the new stat gathered information point has been handled.

Removing the ev_stat_stat() call from the stat_timer_cb() function
definitely solve the issue.

I originally spotted this problem because we perform some slow regular
expression test within the callback.

> Did you read the documentation about stat watchers? Naive use will "lose
> events" and this is not a deficiency in libev, but in the naive usage.

I've read the "The special problem of stat time resolution" that is
described in the ev_stat documentation, but this doesn't come into play
here since the size of the file is changed at each write().


-- 
Yoann Vandoorselaere | Directeur Technique/CTO | PreludeIDS Technologies
Tel: +33 (0)1 40 24 65 10                      Fax: +33 (0)1 40 24 65 28
http://www.prelude-ids.com




More information about the libev mailing list