fix: close streaming responses after upstream errors

This commit is contained in:
tdurieux
2026-09-06 09:19:18 +02:00
parent 38a09188ad
commit b1cb9093bb
3 changed files with 20 additions and 2 deletions
+15
View File
@@ -232,6 +232,21 @@ describe("production regressions", function () {
expect(res.headers["Content-Security-Policy"]).to.include("sandbox");
expect(res.headers["Content-Security-Policy"]).not.to.include("allow-same-origin");
});
it("terminates the streamer response after a late upstream error", async function () {
const input = new (require("stream").PassThrough)();
stub(GitHubStream.prototype, "getFileContentCache", async () => input);
stub(require("../src/server/routes/route-utils"), "handleError", () => {});
const res = new (require("stream").PassThrough)();
res.header = res.contentType = () => res;
res.headersSent = true;
res.resume();
const handler = require("../src/streamer/route").default.stack.find(x => x.route.path === "/").route.stack[0].handle;
await handler({ body: { token: "token", repoFullName: "owner/repo", repoId: "repo", filePath: "file.txt", anonymizerOptions: { filePath: "file.txt", image: true, link: true } } }, res);
input.write("partial data");
input.destroy(new Error("upstream broke"));
await new Promise(resolve => setImmediate(resolve));
expect(res.destroyed).to.equal(true);
});
it("keeps a conference eligible for retry when repository expiration fails", async function () {
const Conference = require("../src/core/Conference").default;
const model = { status: "ready", save: async () => {} };