From 61724cbf325b72b8c7b23cbc496b519e44f109f2 Mon Sep 17 00:00:00 2001 From: Marrrrrrrrry <34876935+Marrrrrrrrry@users.noreply.github.com> Date: Wed, 9 Sep 2026 17:37:06 +0800 Subject: [PATCH] chore: warn at startup when multi-worker deployment weakens in-process rate limiting --- main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.py b/main.py index f860f0c..cab3f23 100644 --- a/main.py +++ b/main.py @@ -77,6 +77,16 @@ async def load_config(): await refresh_settings() await ensure_security_settings() + # Rate limiters keep per-process state (apps.base.dependencies.IPRateLimit). + # With multiple workers each process counts independently, so the effective + # threshold scales with the worker count and resets on restart. + if settings.serverWorkers > 1: + logger.warning( + "serverWorkers=%s:进程内限流在多 worker 下各自独立,阈值将按 worker 数放大;" + "如需完整限流请使用单 worker(默认)或改造为共享存储限流", + settings.serverWorkers, + ) + app = FastAPI(lifespan=lifespan, version=APP_VERSION)