Skip to content

Commit b96582a

Browse files
barjinB4nan
andauthored
fix: session pool leaks memory on multiple crawler runs (#2083)
Fixes #2074 Related #2031 --------- Co-authored-by: Martin Adámek <banan23@gmail.com>
1 parent 75302e0 commit b96582a

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

packages/basic-crawler/src/internals/basic-crawler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
775775
this.running = true;
776776
this.stats.reset();
777777
await this.stats.resetStore();
778+
await this.sessionPool?.resetStore();
778779

779780
await purgeDefaultStorages({ onlyPurgeOnce: true });
780781

packages/core/src/session_pool/session_pool.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ export class SessionPool extends EventEmitter {
290290
return this._createSession();
291291
}
292292

293+
async resetStore() {
294+
await this.keyValueStore?.setValue(this.persistStateKey, null);
295+
}
296+
293297
/**
294298
* Returns an object representing the internal state of the `SessionPool` instance.
295299
* Note that the object's fields can change in future releases.

0 commit comments

Comments
 (0)