@@ -187,9 +187,13 @@ def snapshot(self):
187187async def security_middleware (request , handler ):
188188 """Reject requests to unknown paths with a minimal 404."""
189189 if request .path not in ALLOWED_PATHS :
190- request .app ["_scanner_probes" ] = request .app .get ("_scanner_probes" , 0 ) + 1
190+ probes = request .app .get ("_scanner_probes" )
191+ if probes is None :
192+ probes = {"count" : 0 }
193+ request .app ["_scanner_probes" ] = probes
194+ probes ["count" ] += 1
195+ count = probes ["count" ]
191196 # Log first occurrence per path, then every 100th to avoid flooding
192- count = request .app ["_scanner_probes" ]
193197 if count <= 10 or count % 100 == 0 :
194198 log .warning (
195199 "Blocked probe #%d: %s %s from %s" ,
@@ -540,7 +544,7 @@ async def handle_status(request):
540544 "cache_hits" : rcache .hits ,
541545 "coalesced_total" : coalescer .coalesced_total ,
542546 "coalesced_in_flight" : coalescer .in_flight_count ,
543- "scanner_probes_blocked" : request .app .get ("_scanner_probes" , 0 ),
547+ "scanner_probes_blocked" : request .app .get ("_scanner_probes" , {}). get ( "count" , 0 ),
544548 })
545549
546550
@@ -608,6 +612,8 @@ async def on_startup(app):
608612 app ["tracker" ] = QueueTracker ()
609613 app ["result_cache" ] = ResultCache (ttl_seconds = cache_ttl )
610614 app ["coalescer" ] = RequestCoalescer ()
615+ # Avoid setting attributes after startup (aiohttp deprecation warning)
616+ app ["_scanner_probes" ] = {"count" : 0 }
611617 app ["_cache_cleanup_task" ] = asyncio .ensure_future (_cache_cleanup_loop (app ))
612618
613619 async def on_cleanup (app ):
0 commit comments