Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Added `crashlytics:heapdumps:{enable,disable,status}` commands to manage Crashlytics Android heap dump collection. (#11225)
- Removed unused dependencies `proxy-agent`, `universal-analytics`, and `@apphosting/common`.
- Fixed an issue where throttled task queues stopped processing remaining tasks when a task exhausted its retries or timed out (#6989, #11040).
35 changes: 35 additions & 0 deletions src/deploy/functions/release/executor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from "chai";

import { FirebaseError } from "../../../error";
import RetriesExhaustedError from "../../../throttler/errors/retries-exhausted-error";
import * as executor from "./executor";

describe("Executor", () => {
Expand Down Expand Up @@ -29,7 +30,7 @@
if (throwCount < 2) {
throwCount++;
const err = new Error("Retryable");
(err as any).code = 429;

Check warning on line 33 in src/deploy/functions/release/executor.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type

Check warning on line 33 in src/deploy/functions/release/executor.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .code on an `any` value
return Promise.reject(err);
}
return Promise.resolve(42);
Expand All @@ -41,7 +42,7 @@
it("eventually gives up on retryable errors", async () => {
const handler = (): Promise<void> => {
const err = new Error("Retryable");
(err as any).code = 429;

Check warning on line 45 in src/deploy/functions/release/executor.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type

Check warning on line 45 in src/deploy/functions/release/executor.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .code on an `any` value
throw err;
};
await expect(exec.run(handler)).to.eventually.be.rejectedWith("Retryable");
Expand All @@ -50,7 +51,7 @@
it("retries on custom specified retry predicates", async () => {
const handler = (): Promise<void> => {
const err = new Error("Retryable");
(err as any).code = 8;

Check warning on line 54 in src/deploy/functions/release/executor.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type

Check warning on line 54 in src/deploy/functions/release/executor.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .code on an `any` value
throw err;
};
await expect(
Expand All @@ -65,10 +66,10 @@
const handler = (): Promise<string> => {
attempts++;
if (attempts === 1) {
const err: any = new Error(

Check warning on line 69 in src/deploy/functions/release/executor.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type
"Service account my-sa@project.iam.gserviceaccount.com does not exist",
);
err.status = 404;

Check warning on line 72 in src/deploy/functions/release/executor.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .status on an `any` value
return Promise.reject(err);
}
return Promise.resolve("success");
Expand All @@ -93,8 +94,8 @@
const handler = (): Promise<string> => {
attempts++;
if (attempts === 1) {
const err: any = new Error("Service account not found");

Check warning on line 97 in src/deploy/functions/release/executor.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type
err.status = 404;

Check warning on line 98 in src/deploy/functions/release/executor.spec.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .status on an `any` value
return Promise.reject(err);
}
return Promise.resolve("done");
Expand All @@ -104,6 +105,40 @@
expect(result).to.equal("done");
expect(attempts).to.equal(2);
});

it("drains remaining queued tasks when active tasks exhaust retries under bounded concurrency", async () => {
const boundedExec = new executor.QueueExecutor({
concurrency: 2,
retries: 1,
backoff: 0,
maxBackoff: 1,
});
const attempts: Record<string, number> = {};
const failingTask = (label: string) => (): Promise<string> => {
attempts[label] = (attempts[label] || 0) + 1;
const err = new FirebaseError(`Quota exceeded for ${label}`, { status: 429 });
return Promise.reject(err);
};

const results = await Promise.allSettled([
boundedExec.run(failingTask("fn-1")),
boundedExec.run(failingTask("fn-2")),
boundedExec.run(() => Promise.resolve("fn-3-ok")),
boundedExec.run(() => Promise.resolve("fn-4-ok")),
]);

expect(attempts).to.deep.equal({ "fn-1": 2, "fn-2": 2 });
expect(results[0].status).to.equal("rejected");
if (results[0].status === "rejected") {
expect(results[0].reason).to.be.instanceOf(RetriesExhaustedError);
}
expect(results[1].status).to.equal("rejected");
if (results[1].status === "rejected") {
expect(results[1].reason).to.be.instanceOf(RetriesExhaustedError);
}
expect(results[2]).to.deep.equal({ status: "fulfilled", value: "fn-3-ok" });
expect(results[3]).to.deep.equal({ status: "fulfilled", value: "fn-4-ok" });
});
});

describe("isServiceAccountPropagationError", () => {
Expand Down
65 changes: 65 additions & 0 deletions src/throttler/throttler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,71 @@ const throttlerTest = (ThrottlerConstructor: ThrottlerConstructorType): void =>
expect(q.retried).to.equal(1);
expect(q.total).to.equal(2);
});

it("should continue processing queued tasks after a task fails with RetriesExhaustedError", async () => {
const handler = (task: string): Promise<string> => {
if (task === "fail-task") {
return Promise.reject(TEST_ERROR);
}
return Promise.resolve(`completed:${task}`);
};
const q = new ThrottlerConstructor({
handler,
concurrency: 1,
retries: 1,
backoff: 0,
});

const results = await Promise.allSettled([
q.run("fail-task"),
q.run("queued-task-1"),
q.run("queued-task-2"),
]);

expect(results[0].status).to.equal("rejected");
if (results[0].status === "rejected") {
expect(results[0].reason).to.be.instanceOf(RetriesExhaustedError);
}
expect(results[1]).to.deep.equal({ status: "fulfilled", value: "completed:queued-task-1" });
expect(results[2]).to.deep.equal({ status: "fulfilled", value: "completed:queued-task-2" });
expect(q.complete).to.equal(3);
expect(q.success).to.equal(2);
expect(q.errored).to.equal(1);
expect(q.active).to.equal(0);
});

it("should continue processing queued tasks after a task fails with TimeoutError", async () => {
const handler = (task: string): Promise<string> => {
if (task === "slow-task") {
return new Promise<string>(() => {
// Intentionally never resolves so Throttler's timeout triggers without leaving a timer.
});
}
return Promise.resolve(`completed:${task}`);
};
const q = new ThrottlerConstructor({
handler,
concurrency: 1,
retries: 0,
});

const results = await Promise.allSettled([
q.run("slow-task", 10),
q.run("fast-task-1", 500),
q.run("fast-task-2", 500),
]);

expect(results[0].status).to.equal("rejected");
if (results[0].status === "rejected") {
expect(results[0].reason).to.be.instanceOf(TimeoutError);
}
expect(results[1]).to.deep.equal({ status: "fulfilled", value: "completed:fast-task-1" });
expect(results[2]).to.deep.equal({ status: "fulfilled", value: "completed:fast-task-2" });
expect(q.complete).to.equal(3);
expect(q.success).to.equal(2);
expect(q.errored).to.equal(1);
expect(q.active).to.equal(0);
});
};

describe("Throttler", () => {
Expand Down
1 change: 1 addition & 0 deletions src/throttler/throttler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export abstract class Throttler<T, R> {
}
this.cleanupTask(cursorIndex);
this.finish(error);
Comment thread
ajperel marked this conversation as resolved.
Resolved
this.process();
}

private cleanupTask(cursorIndex: number): void {
Expand Down
Loading