Skip to content

Commit

Permalink
fix: session pool leaks memory on multiple crawler runs (#2083)
Browse files Browse the repository at this point in the history
Fixes #2074
Related #2031

---------

Co-authored-by: Martin Adámek <banan23@gmail.com>
  • Loading branch information
barjin and B4nan committed Sep 20, 2023
1 parent 75302e0 commit b96582a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/basic-crawler/src/internals/basic-crawler.ts
Expand Up @@ -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 });

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/session_pool/session_pool.ts
Expand Up @@ -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.
Expand Down

0 comments on commit b96582a

Please sign in to comment.