[pmg-devel] [PATCH pmg-api 4/4] pmg-smtp-filter: die if processing took longer than the timeout

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Jan 12 10:19:02 CET 2024


Am 11/09/2023 um 16:23 schrieb Stoiko Ivanov:
> In case a mail took longer to get processed than the configured
> timeout - 1 second - `die` before running any action.
> 
> The `die` results in a temporary failure to be reported to the sending
> server by PMG::SMTP.pm ("451 4.4.0 detected undelivered mail").
> 
> The reason for the 1s extra slack is to have some time to actually
> run the action - and also justified that in both cases (postfix
> detecting the timeout, and pmg-smtp-filter `die`ing the sender gets
> a temporary failure reported back).
> 
> Tested with a small filter_timeout setting (30), and a larger sleep in
> analyze_virus added in analyze virus.
> 
> Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
> ---
>  src/bin/pmg-smtp-filter | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/src/bin/pmg-smtp-filter b/src/bin/pmg-smtp-filter
> index 011dd16..1c2c816 100755
> --- a/src/bin/pmg-smtp-filter
> +++ b/src/bin/pmg-smtp-filter
> @@ -316,6 +316,12 @@ sub apply_rules {
>  
>      my $mod_group = PMG::ModGroup->new($entity, $msginfo->{targets});
>  
> +    my $processing_time = int(tv_interval($msginfo->{starttime}));
> +    my $filter_timeout = $self->{pmg_cfg}->get('mail', 'filter_timeout');
> +    if ( ($processing_time - 1) >= $filter_timeout) {

style nit: extra whitespace after the opening parenthesis of the if expression
and the first parenthesis of the actual expression, here you actually would not
need any parenthesis at all, i.e., either like now:

 if ($processing_time - 1 >= $filter_timeout) {

or by optimizing the substraction away by switching to greater-than:

 if ($processing_time > $filter_timeout) {

or a post-if:

die "processing took $processing_time s, longer than the timeout ($filter_timeout)\n"
    if $processing_time > $filter_timeout;


Which I would prefer for that quite simple check, but no hard feelings.

> +	die "processing took $processing_time s, longer than the timeout ($filter_timeout)\n";
> +    }
> +
>      foreach my $rule (@$rules) {
>  	my $targets = $rule_targets{$rule->{id}};
>  	next if !$targets;





More information about the pmg-devel mailing list