kumo scheduling restarts

Hi, sorry for asking this during the weekend, but maybe someone in this awesome community, might know something.

My client reached monthly volume and I have logic for rejecting messages when the limit is reached in the smtp_server_mail_from event:

kumo.on('smtp_server_mail_from', function(sender, conn_meta)
    ...
    local sent = conn:query("INCRBY", 'tenant_sent:' .. conn_meta:get_meta('tenant'), 1)
    local volume = tonumber(conn_meta:get_meta('tenant_volume'))
    if tonumber(sent) > volume then
        kumo.reject(420, 'monthly limit reached')
    end
end)

because of this logic, my guess is that the reject is causing this

May 18 11:41:36 s11462067 kumod[1023790]: called `Option::unwrap()` on a `None` value
May 18 11:41:36 s11462067 kumod[1023790]: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
May 18 11:41:36 s11462067 systemd[1]: kumomta.service: Main process exited, code=dumped, status=3/QUIT
May 18 11:41:36 s11462067 systemd[1]: kumomta.service: Failed with result 'core-dump'.
May 18 11:41:37 s11462067 systemd[1]: kumomta.service: Scheduled restart job, restart counter is at 76.
May 18 11:41:37 s11462067 systemd[1]: Stopped KumoMTA SMTP service.
May 18 11:41:37 s11462067 systemd[1]: Started KumoMTA SMTP service.
May 18 11:41:37 s11462067 kumod[1023870]: 2024-05-18T11:41:37.122869Z  INFO localset-0 kumod: NodeId is 11a465d0-6dad-49ee-a818-5323bb30e5b7
May 18 11:41:37 s11462067 kumod[1023870]: 2024-05-18T11:41:37.285866Z  INFO localset-0 kumod::smtp_server: smtp listener on 0.0.0.0:587
May 18 11:41:37 s11462067 kumod[1023870]: 2024-05-18T11:41:37.298675Z  INFO localset-0 kumod::spool: start_spool: enumeration done, spooled in 38 msgs over 14.053072ms

I figured that rejecting new messages, should be done before smtp_server_mail_from, maybe in the smtp_server_auth_plain, but I need to differentiate between auth fail and limit reach responses.

Hey there @yummy-echidna, thanks for posting. Please read the “Troubleshooting” and “How to Ask for Help” buttons below. If you would like a 1:1 support session from the KumoMTA team, details are at the “Book a Support Session” button below.

You should be able to call a reject anywhere. Please provide your full configs so we can test.

this is the config
init.lua (17.5 KB)

May 18 14:19:21 s11462067 kumod[1069874]: thread 'localset-5' panicked at crates/kumod/src/smtp_server.rs:1184:54:
May 18 14:19:21 s11462067 kumod[1069874]: called `Option::unwrap()` on a `None` value
May 18 14:19:21 s11462067 kumod[1069874]: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
May 18 14:19:21 s11462067 systemd[1]: kumomta.service: Main process exited, code=dumped, status=3/QUIT
May 18 14:19:21 s11462067 systemd[1]: kumomta.service: Failed with result 'core-dump'.
May 18 14:19:21 s11462067 systemd[1]: kumomta.service: Scheduled restart job, restart counter is at 311.
May 18 14:19:21 s11462067 systemd[1]: Stopped KumoMTA SMTP service.
May 18 14:19:21 s11462067 systemd[1]: Started KumoMTA SMTP service.
May 18 14:19:21 s11462067 kumod[1070143]: 2024-05-18T14:19:21.325753Z  INFO localset-3 kumod: NodeId is 11a465d0-6dad-49ee-a818-5323bb30e5b7
May 18 14:19:21 s11462067 kumod[1070143]: 2024-05-18T14:19:21.493782Z  INFO localset-3 kumod::smtp_server: smtp listener on 0.0.0.0:587
May 18 14:19:21 s11462067 kumod[1070143]: 2024-05-18T14:19:21.524972Z  INFO localset-3 kumod::spool: start_spool: enumeration done, spooled in 33 msgs over 31.797281ms

this started when the limit was reached and I figured it might be due to the reject method call

in /opt/kumomta/sbin/kcli trace-smtp-server
i also get this

[*.*.*.*:26420->*.*.*.*:587]    1s === smtp_server_mail_from: Error: callback error
stack traceback:
    [C]: in function 'kumo.reject'
    [string "/opt/kumomta/etc/policy/init.lua"]:314: in function <[string "/opt/kumomta/etc/policy/init.lua"]:298>
caused by: 550 monthly limit reached
[*.*.*.*:26420->*.*.*.*:587]    1s <-  550 monthly limit reached
Error: WebSocket protocol error: Connection reset without closing handshake

Caused by:
    Connection reset without closing handshake
root@s11462067:~#

i changed also kumo.reject(420, 'monthly limit reached') to kumo.reject(550, 'monthly limit reached') and now reception logs are not generated anymore, but the restart keeps happening

i need to mention that i am using the latest stable version Release 2023.12.28-63cde9c7

Please switch to the -dev, there’s a lot of fixes since that version.

will do

Ah, interesting; I think the client is issuing a RCPT TO outside of a transaction and we’re not gracefully handling that case

Fixed in fix: panic if rcpt to issued outside of a transaction · KumoCorp/kumomta@1530c6c · GitHub
That will be available as a dev build in about an hour

FWIW, this issue only occurs if the client is ignoring the errors raised during MAIL FROM and proceeds to RCPT TO anyway

Oh that is interesting. I had not tested that case. Someone out edged my edge case!

on the plus side, it doesn’t let you rcpt to without a mail from!

hy guys,
just upgraded to dev
root@s11462067:~# /opt/kumomta/sbin/kumod --version
kumod 2024.05.17-3f480c94

still getting the restarts

you need to wait a little bit longer for the -1530c6 version to build and publish

my “luck” is that the client is the only client and these restarts do not affect others :grinning_face_with_smiling_eyes: