Fix Rate limiter panics when periods under 1 second are used

This commit is contained in:
Maurus Decimus
2026-06-06 11:24:55 +02:00
parent d0b0cb9438
commit bfd8e2cfc6
2 changed files with 4 additions and 2 deletions

View File

@@ -17,6 +17,7 @@ If you are upgrading from v0.16.x, replace the binary (or run `docker pull`). If
- Disabled aliases continue receiving messages. - Disabled aliases continue receiving messages.
- JMAP for File Storage: `FileNode/get` returns a stale state string. - JMAP for File Storage: `FileNode/get` returns a stale state string.
- Make `SieveSystemInterpreter.defaultReturnPath` and `MtaQueueQuota.match` optional expressions. - Make `SieveSystemInterpreter.defaultReturnPath` and `MtaQueueQuota.match` optional expressions.
- Rate limiter panics when periods under 1 second are used.
## [0.16.7] - 2026-05-28 ## [0.16.7] - 2026-05-28

View File

@@ -301,8 +301,9 @@ impl InMemoryStore {
soft_check: bool, soft_check: bool,
) -> trc::Result<Option<u64>> { ) -> trc::Result<Option<u64>> {
let now = now(); let now = now();
let range_start = now / rate.period.as_secs(); let period = rate.period.as_secs().max(1);
let range_end = (range_start * rate.period.as_secs()) + rate.period.as_secs(); let range_start = now / period;
let range_end = (range_start * period) + period;
let expires_in = range_end - now; let expires_in = range_end - now;
let mut bucket = Vec::with_capacity(key.len() + U64_LEN + 1); let mut bucket = Vec::with_capacity(key.len() + U64_LEN + 1);