I should have included more information. OS is FreeBSD 13.2. smtpd is 7.3.0 
which is the latest in the pkg collection.
Originally, the only change I made to the filter, was add 
#!/usr/local/bin/python3.9 and made afilter.py executable.
All other filters terminate correctly when smtpd exits.

filter afilter proc-exec "/data/afilter.py"
listen on bridge20 port smtp tls pki mail.tekrealm.net auth-optional 
<credentials> filter { afilter, trusted, check_dyndns, check_rdns, 
check_fcrdns, senderscore, rspamd }
listen on bridge20 port smtps smtps pki mail.tekrealm.net auth <credentials> 
mask-src filter { afilter, rspamd }
action "outbound" relay helo mail.tekrealm.net filter "afilter"

Ultimately, I was able to get it to exit correctly after the confirmation that 
it should exit when stdin closes.
I will submit a patch to the github repo after I beat on this for a few days or 
so.

Thank you for your assistance.
-Andrew

-----Original Message-----
From: Tassilo Philipp <[email protected]> 
Sent: Tuesday, April 2, 2024 1:22 AM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: Re: How to terminate smtpd filters?

I agree with Gilles, your filter should react on stdin closing, but not sure 
how your filter is set up.

Also, just a guess... are you running smtpd on Linux?

Linux doesn't kill children when the parent process dies, maybe that's related? 
(To make it do that prctl(2) would need to be used w/
PR_SET_PDEATHSIG.)


On Tue, Apr 02, 2024 at 06:53:39AM +0000, [email protected] wrote:
> April 2, 2024 4:47 AM, [email protected] wrote:
>
>> What signals a termination for smtpd filters?
>>
>> I'm using the code at
>> https://github.com/Beutlin/howto-opensmtpd-filters-and-reports,
>> Which works great, except for when smtpd gets shutdown. The script 
>> continues to run and consumes up to 100% cpu time, while keeping the 
>> smtpd parent? process running.
>>
>> I've tried adding a SIGTERM handler to the code which didn't work, as 
>> well as I saw mentioned that the filter should exit on EOF, so I 
>> tried wrapping
>> parser.dispatch() in
>> a try/except EOFError and using sys.exit. That didn't work either.
>>
>> I've read smtpd-filters, and looked at various other filters and I am 
>> not understanding what tells the filter to shutdown.
>>
>
> The filter is connected to smtpd through its stdin, so it can 
> terminate when there's an EOF on stdin.
>
> This is the proper way to do it and how all filters I wrote work but 
> maybe a bug has crawled in the handling of filter termination and it 
> went unnoticed, I don“t think I ever terminated smtpd in years besides system 
> restarts.
>
> What system are you running on ?
>


Reply via email to