797 Commits

Author SHA1 Message Date
Wez Furlong 29e4ec312d provide helpful reminder that bouncing is async
closes: https://github.com/KumoCorp/kumomta/issues/191
2024-05-30 16:46:03 -07:00
Wez Furlong 1530c6c02e fix: panic if rcpt to issued outside of a transaction 2024-05-18 08:47:36 -07:00
Wez Furlong cbcf5746f5 docs: fix broken doc build 2024-05-17 07:50:03 -07:00
Wez Furlong 03dfa7e870 docs: changelog for https://github.com/KumoCorp/kumomta/pull/179 2024-05-17 07:49:48 -07:00
Wez Furlong a55f726471 docs: utopia openapi doc description updates
The auto-generator changed how it splits the brief/full description
up when rendering it into the openapi spec.
2024-05-17 07:44:39 -07:00
Wez Furlong 8cdadb036c ready_queue: fixup connection goal calculation
I noticed this recently during some testing; for large queue sizes
and large connection limits, we could end up opening more connections
than we currently have queued messages to deliver.

The issue was that the `.min()` constraint was placed on the wrong
term of the calculation, clamping prior to scaling, instead of
after scaling.
2024-05-07 07:24:46 -07:00
Wez Furlong b8a0b26936 NEW: kcli top
This will shows some TUI sparkline charts of major system metrics
over time.
2024-05-04 13:13:09 -07:00
Wez Furlong e48bcd3b57 return 550 for relay_to=false, log_oob=true case
When `log_arf` or `log_oob` are set to true with `relay_to=false`, we
now return a 550 error response for messages that are not ARF or OOB
reports.  Previously, we would return a 250 response and silently drop
the message in this case, which gave the false impression that it was
accepted for relaying.

Expand integration test to explicitly assert that the right things
are allowed/denied/relayed/parsed.
2024-05-02 11:45:07 -07:00
Wez Furlong 4dad617d14 remove EgressPathConfig::suspended logic
When this was added, it was to enable TSA daemon to express
and convey that a given path should be suspended.

The implementation was objectively unpleasant, turning the
fast path of egress source assignment from a simple single
iteration of the weighted round robin logic to N (where N
is the number of sources in a pool) iterations to try
and figure out if a suspension is active.

Now that we have TSA subscriptions that update the admin
suspension information in realtime, we can now simply
rely on that source of information.

This commit removes the logic associated with the deprecated
suspended flag and tidies up the code, making that fast
path a little more fast, and making the code a bit easier
to reason about.
2024-05-02 06:18:14 -07:00
Tom Mairs 413590e22b add notes for starting and enabling tsa daemon 2024-04-30 23:45:10 +00:00
Mike Hillyer 3ec640a1d4 Update FAQ to make it clear about directory access permissions. 2024-04-29 13:33:00 -04:00
Wez Furlong 9e95303e6b add kumo.available_parallelism()
This can be helpful for writing configuration files for systems
that scale to the available compute resources.
2024-04-29 08:23:27 -07:00
Wez Furlong 850b64d48c fix: ready queue gets stuck when TSA suspends before MAIL FROM
This sequence of events:

1. Messages are flowing
2. The remote site starts to return a 421 for mail at connection
   time, prior to MAIL FROM, on new connections
3. The local site employs a TSA rule that suspends the corresponding
   ready queue

Could result in the contents of that ready_queue getting stuck.

Here's a representation of the logs:

```
Apr 24 19:03:44 maintain SITENAME: computed ideal connection count as 3
Apr 24 19:03:44 Error in Dispatcher::run for SITENAME: connect to ResolvedAddress { name: "smtp-in.orange.fr.", addr: 80.12.26.32 } port 25 and read initial banner: Command rejected Response { code: 421, enhanced_code: None, content: "XXXXX smtp.orange.fr XXXXX Service refuse. Veuillez essayer plus tard. Service refused, please try later. OFR_999 [999]", command: None } (consecutive_connection_failures=1)
Apr 24 19:03:45 maintain SITENAME: there are now 3 connections, suspended(via config)=false, suspended(admin)=false, queue_size=691
Apr 24 19:03:45 maintain SITENAME: computed ideal connection count as 3
Apr 24 19:03:45 maintain SITENAME: there are now 3 connections, suspended(via config)=false, suspended(admin)=true, queue_size=746
... the above repeats every minute for a while ...
Apr 24 19:03:45 maintain SITENAME: computed ideal connection count as 0
Apr 24 19:13:45 maintain SITENAME: there are now 3 connections, suspended(via config)=false, suspended(admin)=true, queue_size=746
Apr 24 19:13:45 maintain SITENAME: computed ideal connection count as 0
Apr 24 19:13:45 reaping site SITENAME
Apr 24 19:23:44 maintain SITENAME: there are now 0 connections, suspended(via config)=false, suspended(admin)=false, queue_size=1
```

There are two problems:

1. The main mechanism that acts to sweep the read queue into the
   scheduled queue is only triggered once we get past the initial
   connection phase, causing messages to be retained in the
   ready queue instead of moving back into the scheduled queue.
2. The is-reapable logic doesn't consider the number of messages
   that may be in the ready queue. It was written before we had
   a suspension concept and only considers that an ideal connection
   count of 0 implies that there are no messages.
   The result is, in combination with 1, is that we can reap the ready
   queue while it contains messages and forget about them until
   the server is restarted.

This commit resolves both of these issues:

1. The maintain routine will now act to sweep messages into the
   corresponding scheduled queue if an admin suspension is active.
   In addition, this same sweep is considered when we reap the
   ready queue, just in case some other logic bug manifests in
   the future with the same consequences.
2. The reap logic now also requires that the ready queue be empty.
2024-04-25 07:23:39 -07:00
Wez Furlong a768c6dc79 update-openapi.sh: only run when jq is available
This script is triggered as part of `make test` which is not
really a great place for it.

Its purpose is to extract the auto-generated openapi spec
from the kumod and tsa binaries and update the snapshot
that is present in the docs.

It needs kumod and tsa-daemon to have been built in debug mode
to run successfully.

It piggy-backs on `make test` on the assumption that it will
cause the person who is making changes to it to include those
spec updates in their commit/PR.

Since `make test` invokes it, the various builders may try
and fail to execute jq in the `test` step.  This is mostly
harmless, but looks noisy in the logs.

The ideal situation for this would be:

* at PR time and push time: add a check that runs this script and that
  fails if the specs are updated for the docs and are not part of the PR
  itself. (eg: status is dirty after running it).
  This way it will be visible from the CI state that something is awry.
2024-04-20 07:17:02 -07:00
Wez Furlong 3261d1517f redis: add connect_timeout option
closes: https://github.com/KumoCorp/kumomta/issues/168
2024-04-19 12:33:23 -07:00
Wez Furlong 3ad5856021 memoize: add thundering herd protection
If many calls are made to the memoized function with the same parameters
at the time that the cache is empty/expired, then each of those
concurrent calls will proceed to compute and populate the cache.  This
is known as a thundering herd, and can be painful if the amount of work
performed by the cache population function is high, or alternatively, if
the level of concurrency is high and some system resource is required to
satisfy the call, this can put the system under higher pressure.

This commit adds a simple mechanism to mitigate this: each combination
of cache and cache parameters is paired with an optional semaphore that
is used to constrain concurrency to a single call. This could be a
mutex, but using a semaphore allows future explicit control over the
concurrency level.
2024-04-19 09:11:51 -07:00
Wez Furlong b4aa4a38ec http: allow controlling some timeout and diagnostics on the client
Adds a couple of options that provide more control over the default
timeouts and logging.

These are exposed to the shaping helper as `publish_timeout`,
`publish_pool_idle_timeout` and `publish_connection_verbose`.
2024-04-19 07:44:19 -07:00
Mike Hillyer 080b38d9ad Add a warning to the webhooks helper about proper positioning of the log hooks and queue helper calls. 2024-04-16 14:57:09 -04:00
Wez Furlong e0326e4c39 queue: make bounce_all do spool removal async
I think we've gone back and forth on this a couple of times.
The motivation for this commit is that we've been troubleshooting
an issue that seems to be triggered by bouncing all the mail.
The symptom is that the system becomes unresponsive after
triggering the bounce.

Here in the context of `bounce_all`, the queue lock is held
so that we can capture the messages, but then we serially
remove them from the spool, so that we can report the total
number back to the originating HTTP request.

For a large queue size that presents a big point of contention
for other tasks or requests that may need to operate on the
queue.

This commit moves that spool removal into another task so that
that task can run asynchronously and independently from the
bounce HTTP request.

The consequence of this is that the numbers reported by the
bounce request will likely be lower than the final count.
The `bounce-list` kcli command can be used to check up on
those numbers.
2024-04-10 08:10:03 -07:00
Wez Furlong 0a831f60de mta-sts: reduce scope of cache lock
We've been troubleshooting a lockup on a system with a low core count.
What we found in a stack trace was that one of the threads was blocking
on the CACHE mutex in the sts logic.  That mutex is intended to be
short-duration in scope, managing the direct lookup or insertion
into the cache, and no more.

However, due to the the way that rust scopes the lifetime of the
MutexGuard that is acquired from the CACHE, we were holding it
across the async DNS operation that is used to validate that
a cached policy is still current.

This can result in a deadlock on a system with a sufficiently
low core count/high enough concurrent volume of traffic to sites
with MTA-STS enabled.

This commit resolves this by introducing a lookup function that
explicitly clones the cached policy without returning a MutexGuard.
2024-04-10 07:23:03 -07:00
Wez Furlong e81a5fb6ca fix: msg:set_scheduling didn't immediately recompute due time 2024-04-09 14:34:38 -07:00
Mike Hillyer d282ac61ac Documenting Add support for Routing_Domain in the Queues helper. #141 2024-04-08 13:17:17 -04:00
Mike Hillyer c3cf0d4666 Update shaping based on Comcast documents, add stack trace information to the documentation. 2024-04-03 10:08:43 -04:00
Wez Furlong 898ed52410 add msg:append_text_html and msg:append_text_html
These can be used to insert tracking pixels/links.

closes: https://github.com/KumoCorp/kumomta/issues/120
2024-03-31 14:04:46 -07:00
Wez Furlong 1fb712e2bf Add msg:set_data()
This method allows replacing the message payload arbitrarily.
This is a building block for more advanced and convenient
modification operations.

refs: https://github.com/KumoCorp/kumomta/issues/117
refs: https://github.com/KumoCorp/kumomta/issues/120
2024-03-31 06:57:59 -07:00
Wez Furlong edc56226f7 docs: always pull upstream mkdocs 2024-03-31 06:49:14 -07:00
Wez Furlong e94506fd96 Add new Rejection log event
We skip logging the 421 we generate while shutting down because
it feels a bit redundant; you'll see the server shutting down
in the journal anyway.

refs: https://github.com/KumoCorp/kumomta/issues/88
2024-03-29 16:37:37 -07:00
Wez Furlong 3207c45f3d expose inject_v1 API via lua
closes: https://github.com/KumoCorp/kumomta/issues/102
2024-03-29 09:06:54 -07:00
Wez Furlong 755eb848e2 add glob, read_dir
closes: https://github.com/KumoCorp/kumomta/issues/161
2024-03-29 08:25:51 -07:00
Wez Furlong 0c5794ba31 TSA: Add SuspendTenant, SuspendCampaign
refs: https://github.com/KumoCorp/kumomta/issues/113
2024-03-28 13:08:45 -07:00
Wez Furlong e41b4297ea tsa: hook up websocket suspension stream
This commit connects the new websocket based suspension feed
up to shaping.lua. This allows ready-q suspensions to be
enacted in realtime, as well as sets things up to support
scheduled queue suspensions in a later commit.

refs: https://github.com/KumoCorp/kumomta/issues/113
2024-03-28 07:14:36 -07:00
Wez Furlong 39de0e33a6 Expose suspension API to lua
This is very similar to the HTTP suspension API, with the
difference that the suspend method returns just the uuid rather
than the entire suspension object.

refs: https://github.com/KumoCorp/kumomta/issues/113
2024-03-28 07:14:35 -07:00
Wez Furlong be80391239 add kumo.http.connect_websocket
refs: https://github.com/KumoCorp/kumomta/issues/113
2024-03-28 07:14:35 -07:00
Wez Furlong 6003976a10 new: kumo.spawn_task function
This function will spawn a new thread that runs a tokio
localset, which in turn will trigger the specified event
and run it.

On it's own it doesn't do a lot, but it provides a way
to perform background tasks in lua.

```lua
kumo.on('init', function()
  kumo.spawn_task {
    event_name = 'my.task',
    args = { 'hello', 'there' },
  }
end)

kumo.on('my.task', function(args)
  -- Prints: `I am the task.  ["hello","there"]`
  print('I am the task.', kumo.json_encode(args))
end)
```
2024-03-28 07:14:35 -07:00
Wez Furlong 889cd8223a fix smtp client idle behavior
The intent of the idle behavior is to linger for up to the configured
idle_timeout value, waiting for new messages to arrive in the ready
queue.

The actual behavior was to initiate a wait, but when woken up,
if there were no messages in the ready queue, the connection
would close out, even if there was still time that could be
waited out before the idle period was up.

This commit adds in a loop that will keep the connection open
until the idle timeout is reached, which in turn will improve
throughput, especially if the traffic is a little bursty.
2024-03-27 16:33:18 -07:00
Wez Furlong abd030cc2c docs: changelog for #157
refs: #157
2024-03-25 14:56:41 -07:00
Wez Furlong f54922b9f0 strip enhanced status code from multi-line responses
Previously we would only remove it from the first line.  This commit
removes it from the second and subseqent lines as well.

The bulk of this commit was a little bit of refactoring to favilitate
testing this change.

refs: #157
2024-03-25 11:55:52 -07:00
Wez Furlong f6f8c55ea4 listener_domains: fix fallback issue
This commit refactors listener_domains.lua to facilitate unit testing
and adds a couple of basic test cases.

The functional change here is that we were missing an explicit
fallback step in the case where no listener or domain matches
the provided values directly; we need to explicitly add a check
against the `*` listener AND `*` domain for the final step.
Previously, we would only look at the `*` listener for the final
step.

closes: #128
2024-03-22 09:48:18 -07:00
Wez Furlong a209a470ff docs: clarify how to access headers in logging templates 2024-03-22 08:08:14 -07:00
Wez Furlong c44d7feee7 docs: changelog for #155 2024-03-20 08:27:46 -07:00
Wez Furlong cb94ad00b0 docs: fix link 2024-03-17 09:36:16 -07:00
Wez Furlong 5596d7cf99 http_listener: allow configuring max request size 2024-03-17 09:35:02 -07:00
Wez Furlong 5063a4671b docs: format generate-toc.py 2024-03-17 07:24:34 -07:00
Tom Mairs d961be87bf Update KumoProxy install instructions 2024-03-15 16:51:35 -06:00
Tom Mairs d285a7f71a Update timeout defaults 2024-03-15 15:18:06 -06:00
Mike Hillyer dbb27a6037 Fixing relative URLs. 2024-03-15 16:39:54 -04:00
Mike Hillyer 37efa0e500 Correct link paths and spelling. 2024-03-15 16:32:20 -04:00
Wez Furlong 5a1999a1b1 Add kumo.make_throttle and throttle_insert_ready_queue event
These allow performing arbitrary rate limiting operations
at both reception time and when messages are moved from the
scheduled queue and into the ready queue.

refs:  https://github.com/KumoCorp/kumomta/issues/149
2024-03-15 12:21:57 -07:00
Tom Mairs 18b0520ca8 typo correction 2024-03-15 13:15:46 -06:00
Tom Mairs 7a7919a9f5 fix URLS 2024-03-15 12:54:02 -06:00