Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/core/src/storages/request_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,10 @@ export abstract class RequestProvider implements IStorage, IRequestManager {
protected _reset() {
this.lastActivity = new Date();
this.queueHeadIds.clear();
this.recentlyHandledRequestsCache.clear();
// NOTE: recentlyHandledRequestsCache is intentionally NOT cleared here.
// Clearing it causes handled requests to be refetched from the server
// after a watchdog reset, since listHead() may still return them due to
// server-side consistency delays.
this.assumedTotalCount = 0;
this.assumedHandledCount = 0;
this.requestCache.clear();
Expand Down
35 changes: 35 additions & 0 deletions test/core/storages/request_queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,41 @@ describe('RequestQueue remote', () => {
expect(deleteMock).toHaveBeenLastCalledWith();
});

test('should not refetch handled requests after watchdog reset (V3)', async () => {
const queue = new RequestQueue({ id: 'v3-test', client: storageClient });
const requestA = new Request({ url: 'http://example.com/a' });

vitest.spyOn(queue.client, 'addRequest').mockResolvedValueOnce({
requestId: 'a',
wasAlreadyHandled: false,
wasAlreadyPresent: false,
});
await queue.addRequest(requestA, { forefront: true });

vitest.spyOn(queue.client, 'getRequest').mockResolvedValueOnce({ ...requestA, id: 'a' });
const fetched = await queue.fetchNextRequest();

vitest.spyOn(queue.client, 'updateRequest').mockResolvedValueOnce({
requestId: 'a',
wasAlreadyHandled: false,
wasAlreadyPresent: true,
});
await queue.markRequestHandled(fetched!);

// Simulate watchdog reset (isFinished() calls _reset() after inactivity timeout)
queue['_reset']();

// Cache must survive reset — it's the only guard against server returning stale handled requests
expect(queue['recentlyHandledRequestsCache'].get('a')).toBe(true);

vitest.spyOn(queue.client, 'listHead').mockResolvedValueOnce({
items: [{ id: 'a', uniqueKey: 'aaa' }],
} as never);

const refetched = await queue.fetchNextRequest();
expect(refetched).toBe(null);
});

test('Request.userData.__crawlee internal object is non-enumerable and always defined', async () => {
const url = 'http://example.com';
const method = 'POST';
Expand Down