chore: warn at startup when multi-worker deployment weakens in-process rate limiting

This commit is contained in:
Marrrrrrrrry committed 2026-09-09 17:37:06 +08:00
1 parent 6587ec86be
commit 61724cbf32
1 file changed
+10
+10
View File
@@ -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)