Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

fix: session pool leaks memory on multiple crawler runs (#2083)

Jindřich Bärb96582a200e2
diff --git a/packages/basic-crawler/src/internals/basic-crawler.ts b/packages/basic-crawler/src/internals/basic-crawler.ts
index 24df8d0d3..1f4960c1f 100644
--- a/packages/basic-crawler/src/internals/basic-crawler.ts
+++ b/packages/basic-crawler/src/internals/basic-crawler.ts
@@ -775,6 +775,7 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
this.running = true;
this.stats.reset();
await this.stats.resetStore();
+ await this.sessionPool?.resetStore();
await purgeDefaultStorages({ onlyPurgeOnce: true });
diff --git a/packages/core/src/session_pool/session_pool.ts b/packages/core/src/session_pool/session_pool.ts
index c60878500..31ff548cb 100644
--- a/packages/core/src/session_pool/session_pool.ts
+++ b/packages/core/src/session_pool/session_pool.ts
@@ -290,6 +290,10 @@ export class SessionPool extends EventEmitter {
return this._createSession();
}
+ async resetStore() {
+ await this.keyValueStore?.setValue(this.persistStateKey, null);
+ }
+
/**
* Returns an object representing the internal state of the `SessionPool` instance.
* Note that the object's fields can change in future releases.