Repository: thrift Updated Branches: refs/heads/master bd257f1b9 -> 9019b280e
THRIFT-4065 fix SIGCHLD handling for perl ForkingServer and document restrictions Client: perl This closes #1176 Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/9019b280 Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/9019b280 Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/9019b280 Branch: refs/heads/master Commit: 9019b280eacf0c2cf02d7671a59a9f099b82aa88 Parents: bd257f1 Author: James E. King, III <[email protected]> Authored: Wed Feb 8 20:53:09 2017 -0500 Committer: James E. King, III <[email protected]> Committed: Wed Feb 8 20:53:09 2017 -0500 ---------------------------------------------------------------------- lib/perl/README.md | 8 ++++++++ lib/perl/lib/Thrift/Server.pm | 26 ++------------------------ 2 files changed, 10 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/9019b280/lib/perl/README.md ---------------------------------------------------------------------- diff --git a/lib/perl/README.md b/lib/perl/README.md index e6451ec..0540948 100644 --- a/lib/perl/README.md +++ b/lib/perl/README.md @@ -47,6 +47,14 @@ to wrap eval{} statments around any code that contains exceptions. Please see tutoral and test dirs for examples. +The Perl ForkingServer ignores SIGCHLD allowing the forks to be +reaped by the operating system naturally when they exit. This means +one cannot use a custom SIGCHLD handler in the consuming perl +implementation that calls serve(). It is acceptable to use +a custom SIGCHLD handler within a thrift handler implementation +as the ForkingServer resets the forked child process to use +default signal handling. + Dependencies ============ http://git-wip-us.apache.org/repos/asf/thrift/blob/9019b280/lib/perl/lib/Thrift/Server.pm ---------------------------------------------------------------------- diff --git a/lib/perl/lib/Thrift/Server.pm b/lib/perl/lib/Thrift/Server.pm index ac1e17d..5829e67 100644 --- a/lib/perl/lib/Thrift/Server.pm +++ b/lib/perl/lib/Thrift/Server.pm @@ -235,10 +235,6 @@ sub _parent my $itrans = shift; my $otrans = shift; - # add before collect, otherwise you race w/ waitpid - $self->{children}->{$pid} = 1; - $self->_collectChildren(); - # Parent must close socket or the connection may not get closed promptly $self->tryClose($itrans); $self->tryClose($otrans); @@ -254,6 +250,8 @@ sub _child my $ecode = 0; eval { + # THRIFT-4065 ensure child process has normal signal handling in case thrift handler uses it + $SIG{CHLD} = 'DEFAULT'; while (1) { $self->{processor}->process($iprot, $oprot); @@ -292,24 +290,4 @@ sub tryClose } } -sub _collectChildren -{ - my $self = shift; - - while (scalar keys %{$self->{children}}) - { - my $pid = waitpid(-1, WNOHANG); - - if ($pid>0) - { - delete $self->{children}->{$pid}; - } - else - { - last; - } - } -} - - 1;
