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.

Restored sessions use current pool's maxUsageCount (#1058)

xTRiMffc8926dad93
diff --git a/src/session_pool/session.js b/src/session_pool/session.js
index 915ece726..f0c1e4bb9 100644
--- a/src/session_pool/session.js
+++ b/src/session_pool/session.js
@@ -188,6 +188,7 @@ export class Session {
expiresAt: this.expiresAt.toISOString(),
createdAt: this.createdAt.toISOString(),
usageCount: this.usageCount,
+ maxUsageCount: this.maxUsageCount,
errorScore: this.errorScore,
};
}
diff --git a/test/session_pool/session_pool.test.js b/test/session_pool/session_pool.test.js
index 73697124e..fcc6ab33a 100644
--- a/test/session_pool/session_pool.test.js
+++ b/test/session_pool/session_pool.test.js
@@ -263,6 +263,18 @@ describe('SessionPool - testing session pool', () => {
await newSessionPool.teardown();
});
+ test('should restore persisted maxUsageCount of recreated sessions', async () => {
+ sessionPool = await Apify.openSessionPool({ maxPoolSize: 1, sessionOptions: { maxUsageCount: 66 } });
+ await sessionPool.getSession();
+ await sessionPool.persistState();
+ const loadedSessionPool = new SessionPool({ maxPoolSize: 1, sessionOptions: { maxUsageCount: 88 } });
+ await loadedSessionPool.initialize();
+
+ const recreatedSession = await loadedSessionPool.getSession();
+
+ expect(recreatedSession.maxUsageCount).toEqual(66);
+ });
+
test('should persist state on teardown', async () => {
const persistStateKey = 'TEST-KEY';
const persistStateKeyValueStoreId = 'TEST-VALUE-STORE';