> > I suspect we need a general timeout mechanism for plugin dispatches.
> > Right now, we only timeout input.
> 
> I've raised this issue before - search for thread "smtp connections
> never timeout". Ask acknowledged this as a "pretty serious bug", but I
> don't think there has ever been any followup.
> 
> I don't think we want to add timeout login to each plugin - there
> should be a timeout within dispatch().

I agree.

But do we really want to use signals for it?  If so, it would be
pretty easy to put a simple timeout handler in TcpServer::dispatch().

consider this proof of concept. 

I haven't tried this:

# TcpServer::dispatch
sub dispatch {
  my $self = shift;
  my ($cmd) = lc shift;
  my $result;

  local $SIG{ALRM} = sub {
    die "timeout in plugin '$cmd'\n";
  };

  alarm $self->config("plugin_timeout") || 120;

  $result = $self->SUPER::dispatch(@_);

  if ($@ ~= /^timeout /) {
    $self->fault("timeout dispatching plugin '$cmd'");
  } else {
    die $@ if $@;     # rethrow
  }
  alarm 0;
  return $result;  
}


The eval is necessary to prevent the timeout from killing the entire
program, unless of course that's what we want.  (But I don't think it
is.)

The actual plugin dispatch is also wrapped in an eval, and that will
catch timeouts in the plugin itself.  If for some reason there's a
timeout not inside that inner eval, we'll catch it here.

-R

Reply via email to