public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Stoiko Ivanov <s.ivanov@proxmox.com>, pmg-devel@lists.proxmox.com
Subject: Re: [pmg-devel] [PATCH pmg-api 4/4] pmg-smtp-filter: die if processing took longer than the timeout
Date: Fri, 12 Jan 2024 10:19:02 +0100	[thread overview]
Message-ID: <7a479e8e-8f40-4ca4-8240-47bde77f618c@proxmox.com> (raw)
In-Reply-To: <20230911142317.19746-5-s.ivanov@proxmox.com>

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@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;





  reply	other threads:[~2024-01-12  9:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11 14:23 [pmg-devel] [PATCH pmg-api/docs] make filter timeout configurable Stoiko Ivanov
2023-09-11 14:23 ` [pmg-devel] [PATCH pmg-api 1/4] templates: postfix: set same timeouts for before and after-queue Stoiko Ivanov
2023-09-11 14:23 ` [pmg-devel] [PATCH pmg-api 2/4] pmg-smtp-filter: refactor use of gettimeofday Stoiko Ivanov
2023-09-11 14:23 ` [pmg-devel] [PATCH pmg-api 3/4] config: postfix: make smtp-filter-timeout configurable Stoiko Ivanov
2024-01-12  9:15   ` Thomas Lamprecht
2023-09-11 14:23 ` [pmg-devel] [PATCH pmg-api 4/4] pmg-smtp-filter: die if processing took longer than the timeout Stoiko Ivanov
2024-01-12  9:19   ` Thomas Lamprecht [this message]
2023-09-11 14:23 ` [pmg-devel] [PATCH pmg-docs 1/1] doc-generator: add new option filter_timeout Stoiko Ivanov
2024-01-12  8:35 ` [pmg-devel] [PATCH pmg-api/docs] make filter timeout configurable Dominik Csapak
2024-01-12 19:59   ` Stoiko Ivanov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7a479e8e-8f40-4ca4-8240-47bde77f618c@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    --cc=s.ivanov@proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal