From f9b70eb6ebbf96c2fe79ab2738ea4954c5a124f3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 24 Jun 2017 07:33:44 +0000 Subject: 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. --- script/public-inbox-watch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'script/public-inbox-watch') diff --git a/script/public-inbox-watch b/script/public-inbox-watch index a72180c9..51f1baa2 100755 --- a/script/public-inbox-watch +++ b/script/public-inbox-watch @@ -13,7 +13,7 @@ my $reload = sub { }; $reload->(); if ($watch_md) { - my $scan = sub { $watch_md->scan if $watch_md }; + my $scan = sub { $watch_md->trigger_scan('full') if $watch_md }; $SIG{HUP} = $reload; $SIG{USR1} = $scan; $SIG{ALRM} = sub { $SIG{ALRM} = 'DEFAULT'; $scan->() }; -- cgit v1.2.3-24-ge0c7