diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2025-06-14 14:54:56 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2025-06-14 14:54:56 +0100 |
commit | 5703bd8a98672e3883d53c117168e9097ead66b8 (patch) | |
tree | 13c4100cfdd3d7e508c0307874ca3e243ebc4a2b | |
parent | ee933148f311abc73b4ba8b65893c5b78a572580 (diff) | |
download | rspamd-vstakhov-maps-lock.tar.gz rspamd-vstakhov-maps-lock.zip |
[Minor] Oops, forgot some code to be addedvstakhov-maps-lock
-rw-r--r-- | src/libserver/maps/map.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libserver/maps/map.c b/src/libserver/maps/map.c index 2226a96d3..e0e714d5a 100644 --- a/src/libserver/maps/map.c +++ b/src/libserver/maps/map.c @@ -317,6 +317,7 @@ rspamd_http_map_process_next_check(struct rspamd_map *map, gboolean has_last_modified) { static const time_t interval_mult = 4; /* Reduced from 16 to be more responsive */ + static const time_t min_respectful_interval = 5; time_t next_check; time_t effective_interval = map_check_interval; @@ -374,6 +375,23 @@ rspamd_http_map_process_next_check(struct rspamd_map *map, return next_check; } +/** + * Calculate respectful polling interval to avoid DoS'ing servers with cache validation + * @param map_check_interval user configured interval + * @return effective interval that respects server resources + */ +static inline time_t +rspamd_map_get_respectful_interval(time_t map_check_interval) +{ + static const time_t min_respectful_interval = 5; /* Minimum 5 seconds to be respectful */ + static const time_t interval_mult = 4; /* Multiplier for respectful minimum */ + + if (map_check_interval < min_respectful_interval) { + return min_respectful_interval * interval_mult; + } + return map_check_interval; +} + static int http_map_finish(struct rspamd_http_connection *conn, struct rspamd_http_message *msg) |