From 7113598b78c4a294a3cb8173d408f86455e6920b Mon Sep 17 00:00:00 2001 From: Vlada Dusek Date: Mon, 2 Mar 2026 13:05:50 +0100 Subject: [PATCH] fix(scrapy): Close `AsyncThread` on scheduler `open()` failure If `open_rq()` raises, Scrapy will not call `close()`, so the `AsyncThread` (and its event loop thread) would leak. Close it explicitly before re-raising. Co-Authored-By: Claude Opus 4.6 --- src/apify/scrapy/scheduler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/apify/scrapy/scheduler.py b/src/apify/scrapy/scheduler.py index 2c6945bb..dc3add93 100644 --- a/src/apify/scrapy/scheduler.py +++ b/src/apify/scrapy/scheduler.py @@ -61,6 +61,7 @@ async def open_rq() -> RequestQueue: try: self._rq = self._async_thread.run_coro(open_rq()) except Exception: + self._async_thread.close() traceback.print_exc() raise