mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
fix(release): retry commit history gateway timeouts (#12377)
Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
1 parent
e9af636128
commit
80e8bbc871
3 files changed
+44
-9
No files matched your search
@@ -13,13 +13,13 @@
|
||||
}
|
||||
catch (err) {
|
||||
- if (err.status !== 502) {
|
||||
+ // Only commit-history reads opt in to transient HTTP-200 errors.
|
||||
+ const retryInternalError = options?.retryInternalErrors &&
|
||||
+ // Only commit-history reads opt in to gateway timeouts and transient HTTP-200 errors.
|
||||
+ const retryHistoryError = options?.retryHistoryErrors && (err.status === 504 ||
|
||||
+ err instanceof graphql_1.GraphqlResponseError &&
|
||||
+ err.errors.length > 0 &&
|
||||
+ err.errors.every(error => typeof error.message === 'string' &&
|
||||
+ error.message.startsWith('Something went wrong while executing your query'));
|
||||
+ if (err.status !== 502 && !retryInternalError) {
|
||||
+ error.message.startsWith('Something went wrong while executing your query')));
|
||||
+ if (err.status !== 502 && !retryHistoryError) {
|
||||
throw err;
|
||||
}
|
||||
if (maxRetries === 0) {
|
||||
@@ -27,7 +27,7 @@
|
||||
throw err;
|
||||
}
|
||||
- this.logger.info(`received 502 error, ${maxRetries} attempts remaining`);
|
||||
+ this.logger.info(`received ${err.status === 502 ? '502' : 'internal GraphQL'} error, ${maxRetries} attempts remaining`);
|
||||
+ this.logger.info(`received ${err.status === 502 || err.status === 504 ? err.status : 'internal GraphQL'} error, ${maxRetries} attempts remaining`);
|
||||
}
|
||||
maxRetries -= 1;
|
||||
if (maxRetries >= 0) {
|
||||
@@ -78,7 +78,7 @@
|
||||
query,
|
||||
...params,
|
||||
- });
|
||||
+ }, { retryInternalErrors: true });
|
||||
+ }, { retryHistoryErrors: true });
|
||||
if (!response) {
|
||||
this.logger.warn(`Did not receive a response for query: ${query}`, params);
|
||||
return null;
|
||||
|
||||
@@ -15,8 +15,12 @@ const patch = fileURLToPath(
|
||||
|
||||
export function describeReleaseProposalError(error) {
|
||||
if (!(error instanceof Error)) return String(error);
|
||||
const description = error.message || error.name || "Unknown error";
|
||||
const status = error.status;
|
||||
const description = /^\s*<(?:!doctype\s+html\b|html[\s>])/iu.test(
|
||||
error.message,
|
||||
)
|
||||
? "GitHub returned an HTML error response"
|
||||
: error.message || error.name || "Unknown error";
|
||||
return Number.isInteger(status) && status >= 400 && status <= 599
|
||||
? `${description} (HTTP ${status})`
|
||||
: description;
|
||||
|
||||
@@ -46,6 +46,18 @@ it("reports an HTTP status when a release proposal error has no message", () =>
|
||||
expect(describeReleaseProposalError(new Error("broken"))).toBe("broken");
|
||||
});
|
||||
|
||||
it("reports a gateway error without logging the HTML response page", () => {
|
||||
const failure = Object.assign(
|
||||
new Error("<!DOCTYPE html>\n<html><title>Unicorn!</title></html>"),
|
||||
{
|
||||
status: 504,
|
||||
},
|
||||
);
|
||||
expect(describeReleaseProposalError(failure)).toBe(
|
||||
"GitHub returned an HTML error response (HTTP 504)",
|
||||
);
|
||||
});
|
||||
|
||||
beforeAll(async () => {
|
||||
upstream = await import("release-please");
|
||||
githubRuntime = require("release-please/build/src/github.js");
|
||||
@@ -303,6 +315,7 @@ type HistoryFailure = {
|
||||
cursor?: string;
|
||||
errors: { message: string; type?: string }[];
|
||||
status?: number;
|
||||
html?: string;
|
||||
};
|
||||
const internalError = {
|
||||
message:
|
||||
@@ -482,6 +495,11 @@ async function releaseFixture({
|
||||
const failure = failures[0];
|
||||
if (failure && failure.cursor === query.variables.cursor) {
|
||||
failures.shift();
|
||||
if (failure.html !== undefined)
|
||||
return new Response(failure.html, {
|
||||
status: failure.status ?? 504,
|
||||
headers: { "content-type": "text/html; charset=utf-8" },
|
||||
});
|
||||
return respond(
|
||||
{
|
||||
...historyPage(commits, query.variables, pullRequest),
|
||||
@@ -998,9 +1016,15 @@ it.each([
|
||||
status: 200,
|
||||
},
|
||||
{ name: "HTTP 502 error", error: internalError, status: 502 },
|
||||
{
|
||||
name: "HTTP 504 HTML error",
|
||||
error: internalError,
|
||||
status: 504,
|
||||
html: "<!DOCTYPE html><html><title>Unicorn!</title></html>",
|
||||
},
|
||||
])(
|
||||
"retries the same history cursor after $name and discards partial data",
|
||||
async ({ error, status }) => {
|
||||
async ({ error, status, html }) => {
|
||||
const sleep = vi
|
||||
.spyOn(githubRuntime, "sleepInMs")
|
||||
.mockResolvedValue(undefined);
|
||||
@@ -1012,7 +1036,14 @@ it.each([
|
||||
commits.push({ sha: baseline, message: "chore: release 6.7.0", files: [] });
|
||||
const fixture = await releaseFixture({
|
||||
commits,
|
||||
historyFailures: [{ cursor: "10", errors: [error], status }],
|
||||
historyFailures: [
|
||||
{
|
||||
cursor: "10",
|
||||
errors: [error],
|
||||
status,
|
||||
...(html === undefined ? {} : { html }),
|
||||
},
|
||||
],
|
||||
});
|
||||
const candidates = await fixture.manifest.buildPullRequests();
|
||||
const body = candidates[0]?.body.toString();
|
||||
|
||||
Reference in new issue
Block a user