Skip to content

Commit

Permalink
chore: small inconsistencies fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu committed Aug 25, 2023
1 parent a1b3e95 commit e04e3ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/storages/request_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class RequestQueue extends RequestProvider {
* Returns the request object or `null` if there are no more pending requests.
*/
override async fetchNextRequest<T extends Dictionary = Dictionary>(): Promise<Request<T> | null> {
await this._ensureHeadIsNonEmpty();
await this.ensureHeadIsNonEmpty();

const nextRequestId = this.queueHeadIds.removeFirst();

Expand All @@ -131,7 +131,7 @@ export class RequestQueue extends RequestProvider {
this.requestIdsInProgress.add(nextRequestId);
this.lastActivity = new Date();

let request;
let request: Request | null;
try {
request = await this.getRequest(nextRequestId);
} catch (e) {
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/storages/request_queue_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ class RequestQueue extends RequestProvider {
this.requestIdsInProgress.add(nextRequestId);
this.lastActivity = new Date();

const request = await this.getOrHydrateRequest(nextRequestId);
let request: Request | null;

try {
request = await this.getOrHydrateRequest(nextRequestId);
} catch (e) {
// On error, remove the request from in progress, otherwise it would be there forever
this.requestIdsInProgress.delete(nextRequestId);
throw e;
}

// NOTE: It can happen that the queue head index is inconsistent with the main queue table. This can occur in two situations:

Expand Down

0 comments on commit e04e3ae

Please sign in to comment.