Hello !

I met an issue with milter when multiple messages pushed within single smtp session (using pipelining indeed): warning: milter unix:/run/t.socket: unexpected filter response SMFIR_ADDHEADER after event SMFIC_MAIL

It looks similar for https://www.mail-archive.com/postfix-users@postfix.org/msg13652.html

the issue is nearly 100% reproducible.
my postfix config is simple:
smtpd_milters=unix:/run/t.socket

milter daemon is simple perl code on top of Sendmail::PMilter and does addheader/chgheader at EOM stage.

Then I connect with "telnet 0 25" and pipeline multiple messages (actually four) with header "X-TEST: 1-2-3-4" into postfix.

from postfix milter debug log I learn that 1st message processed like
Dec  3 15:22:33 srv postfix/cleanup[168510]: event: SMFIC_BODYEOB;
macros: i=16C381A1BA2
Dec 3 15:22:34 srv postfix/cleanup[168510]: reply: SMFIR_ADDHEADER data 18 bytes Dec 3 15:22:34 srv postfix/cleanup[168510]: reply: SMFIR_CHGHEADER data 12 bytes Dec 3 15:22:34 srv postfix/cleanup[168510]: reply: SMFIR_CONTINUE data 0 bytes
Dec  3 15:22:34 srv postfix/cleanup[168510]: free milter unix:/run/t.socket

when 2nd (or time-to-time 3rd) fails:
Dec 3 15:22:35 srv postfix/cleanup[168510]: reply: SMFIR_CONTINUE data 0 bytes Dec 3 15:22:35 srv postfix/cleanup[168510]: event: SMFIC_BODYEOB; macros: i=23FA51A1BA9 Dec 3 15:22:35 srv postfix/cleanup[168510]: reply: SMFIR_CONTINUE data 0 bytes
Dec  3 15:22:35 v/cleanup[168510]: free milter unix:/run/smilter/t.socket

Dec 3 15:22:36 srv postfix/smtpd[168502]: reply: SMFIR_ADDHEADER data 17 bytes Dec 3 15:22:36 srv postfix/smtpd[168502]: warning: milter unix:/run/t.socket: unexpected filter response SMFIR_ADDHEADER after event SMFIC_MAIL

Tested on postfix-3.7.3

Is there any way to avoid milter reply disordering ?

full code of test perl milter daemon:
==========================================================
use Sendmail::PMilter qw(:all);
use IO::Socket::INET;

my %cbs;
$cbs{envfrom} = sub { my $ctx = shift; $ctx->setpriv({ c => 0) }); SMFIS_CONTINUE; };

$cbs{envrcpt} = sub { my $ctx = shift;
my $data_ref = $ctx->getpriv();
$data_ref->{c}++;  $ctx->setpriv($data_ref); SMFIS_CONTINUE; };

$cbs{header} = sub {
  my $ctx = shift;
  my $data_ref = $ctx->getpriv();
  if ($args[0] eq 'X-TEST') { $data_ref->{test} = $args[1]; sleep (1); }
  $ctx->setpriv($data_ref);
  SMFIS_CONTINUE;
};

$cbs{eom} = sub {
  my $ctx = shift;
  my $data_ref = $ctx->getpriv();
  sleep(1);
  $ctx->addheader('X-FIX',$data_ref->{test});
  $ctx->chgheader('X-TEST');
  SMFIS_CONTINUE;
};

my $m = new Sendmail::PMilter;
$m->setconn("local:/run/t.socket");
$m->register('t', \%cbs, SMFIF_CHGHDRS|SMFIF_ADDHDRS);
$m->set_dispatcher(Sendmail::PMilter::prefork_dispatcher( max_children => 10, max_requests_per_child => 50 ));
$m->main();

==========================================================


Best Regards,
Deniss

Reply via email to