Skip to content

Commit

Permalink
fix: session pool leaks memory on multiple crawler runs
Browse files Browse the repository at this point in the history
  • Loading branch information
barjin committed Sep 18, 2023
1 parent 0ef6bb1 commit a3c9001
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/basic-crawler/src/internals/basic-crawler.ts
Original file line number Diff line number Diff line change
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
8 changes: 8 additions & 0 deletions packages/core/src/session_pool/session_pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ export class SessionPool extends EventEmitter {
return this._createSession();
}

async resetStore() {
if (!this.keyValueStore) {
return;
}

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 a3c9001

Please sign in to comment.