From: Aaron Crane Date: Thu, 12 Jan 2017 09:45:30 +0000 (+0000) Subject: Catalyst::Restarter::Forking: clear watcher in child process X-Git-Tag: 1.40~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=835133d258cdf1ff5c7f46a3c37230657231e552;p=catagits%2FCatalyst-Devel.git Catalyst::Restarter::Forking: clear watcher in child process This allows any resources held by the watcher to be released in the child process, where they won't be needed. This is particularly important in kqueue-based watcher implementations. The way kqueue works requires an open file descriptor for each file and directory watched. In the case of modules being loaded from a local::lib, this can easily amount to many thousands of file descriptors. This is not only wasteful, but it also prevents select(2) from being called on any file descriptor subsequently opened: you're likely to get EINVAL because the descriptor exceeds FD_SETSIZE. --- diff --git a/Changes b/Changes index bb353dd..92f9a61 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,8 @@ This file documents the revision history for Perl extension Catalyst-Devel. - Typo fixes. RT#87103 + - Catalyst::Restarter::Forking: clear watcher in child process. + RT#119830 1.39 2013-06-14 12:44:17 - Write =encoding utf8 into generated Pod files so that things diff --git a/lib/Catalyst/Restarter.pm b/lib/Catalyst/Restarter.pm index 5ce4ea4..81295f1 100644 --- a/lib/Catalyst/Restarter.pm +++ b/lib/Catalyst/Restarter.pm @@ -22,8 +22,9 @@ has argv => ( ); has _watcher => ( - is => 'rw', - isa => 'File::ChangeNotify::Watcher', + is => 'rw', + isa => 'File::ChangeNotify::Watcher', + clearer => '_clear_watcher', ); has _filter => ( diff --git a/lib/Catalyst/Restarter/Forking.pm b/lib/Catalyst/Restarter/Forking.pm index 40c81f0..a45e516 100644 --- a/lib/Catalyst/Restarter/Forking.pm +++ b/lib/Catalyst/Restarter/Forking.pm @@ -17,6 +17,9 @@ sub _fork_and_start { $self->_child($pid); } else { + # Only the parent process needs to watch for changes, so the child + # should release any resources held by the watcher: + $self->_clear_watcher; $self->start_sub->(); } }