fix(server): 限流中间件 fail-close 安全加固

RateLimitConfig 添加 fail_close 字段(默认 true),Redis 不可达时
拒绝请求返回 503 而非静默放行。开发环境可通过
ERP__RATE_LIMIT__FAIL_CLOSE=false 回退旧行为。
This commit is contained in:
iven
2026-05-11 10:22:05 +08:00
parent 8c347a5de9
commit 0f67f1c21f
3 changed files with 87 additions and 16 deletions

View File

@@ -159,8 +159,26 @@ impl StorageConfig {
}
}
#[derive(Debug, Clone, Deserialize, Default)]
pub struct RateLimitConfig {}
#[derive(Debug, Clone, Deserialize)]
pub struct RateLimitConfig {
/// Redis 不可达时是否拒绝请求fail-close
/// true = 安全优先Redis 故障时返回 503。
/// false = 可用性优先Redis 故障时放行。
#[serde(default = "default_fail_close")]
pub fail_close: bool,
}
fn default_fail_close() -> bool {
true
}
impl Default for RateLimitConfig {
fn default() -> Self {
Self {
fail_close: default_fail_close(),
}
}
}
impl AppConfig {
pub fn load() -> anyhow::Result<Self> {