Some bugfix in CI
This commit is contained in:
@@ -20,11 +20,15 @@ def _reset_all():
|
|||||||
ip_ban_manager.banned_networks.clear()
|
ip_ban_manager.banned_networks.clear()
|
||||||
|
|
||||||
# Suspicious request counts via direct reference stored in app.state
|
# Suspicious request counts via direct reference stored in app.state
|
||||||
|
# Because FastAPI's add_middleware creates a new instance internally,
|
||||||
|
# navigating app.state or app.middleware_stack is unreliable.
|
||||||
|
# We use gc to robustly find the active SecurityMiddleware instance(s) and clear them.
|
||||||
try:
|
try:
|
||||||
from main import app
|
import gc
|
||||||
sm = getattr(app.state, '_security_middleware', None)
|
from guard.middleware import SecurityMiddleware
|
||||||
if sm is not None:
|
for obj in gc.get_objects():
|
||||||
sm.suspicious_request_counts.clear()
|
if isinstance(obj, SecurityMiddleware):
|
||||||
|
obj.suspicious_request_counts.clear()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user