Skip to content

The agent that grows with you

fix(gateway): keep the drain-marker read off the event loop

RFingAdamb6f42c667a59
diff --git a/gateway/run.py b/gateway/run.py
index 177592bbc3d..80cf7e2f4b5 100644
--- a/gateway/run.py
+++ b/gateway/run.py
@@ -9876,7 +9876,12 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
while self._running:
try:
- if drain_requested():
+ # drain_requested() does a synchronous read_text() on the
+ # marker file. At this 1s cadence that puts a blocking disk
+ # read on the event loop ~86k times a day; when the host is
+ # under I/O pressure a single read can stall for 30s+ and
+ # take every platform heartbeat down with it. Off-thread it.
+ if await asyncio.to_thread(drain_requested):
self._enter_external_drain()
# API and cron work live outside messaging's
# _running_agents map. Refresh the aggregate while an