]> Sergey Matveev's repositories - public-inbox.git/commit
watch: improve fairness during full rescans
authorEric Wong <e@80x24.org>
Sat, 24 Jun 2017 07:33:44 +0000 (07:33 +0000)
committerEric Wong <e@80x24.org>
Mon, 26 Jun 2017 03:44:30 +0000 (03:44 +0000)
commitf9b70eb6ebbf96c2fe79ab2738ea4954c5a124f3
tree4f5785aa3252bbf4330c385f652926e48103dc42
parentd9c9dc5af637e097d545a828d887aae99ddcd2a7
watch: improve fairness during full rescans

We need to ensure new messages are being processed
fairly during full rescans, so have the ->scan subroutine
yield and reschedule itself.  Additionally, having a
long-running task inside the signal handler is dangerous
and subject to reentrancy bugs.

Due to the limitations of the Filesys::Notify::Simple interface,
we cannot rely on multiplexing I/O interfaces (select, IO::Poll,
Danga::Socket, etc...) for this.  Forking a separate process
was considered, but it is more expensive for a mostly-idle
process.

So, we use a variant of the "self-pipe trick" via inotify (or
whatever Filesys::Notify::Simple gives us).  Instead of writing
to our own pipe, we write to a file in our own temporary
directory watched by Filesys::Notify::Simple to trigger events
in signal handlers.
lib/PublicInbox/WatchMaildir.pm
script/public-inbox-watch
t/watch_maildir.t