mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-09-17 08:05:25 +02:00
fix: close streaming responses after upstream errors
This commit is contained in:
@@ -172,10 +172,10 @@ async function webView(req: express.Request, res: express.Response) {
|
|||||||
const html = `<!DOCTYPE html><html><head><title>Content</title></head><link rel="stylesheet" href="/css/all.min.css" /><body><div class="container p-3 file-content markdown-body">${body}</div></body></html>`;
|
const html = `<!DOCTYPE html><html><head><title>Content</title></head><link rel="stylesheet" href="/css/all.min.css" /><body><div class="container p-3 file-content markdown-body">${body}</div></body></html>`;
|
||||||
res.contentType("text/html").send(html);
|
res.contentType("text/html").send(html);
|
||||||
} catch {
|
} catch {
|
||||||
f.send(res);
|
await f.send(res);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
f.send(res);
|
await f.send(res);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, res, req);
|
handleError(error, res, req);
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ router.post(
|
|||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, res);
|
handleError(error, res);
|
||||||
|
if (res.headersSent && !res.writableEnded) res.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -111,6 +112,8 @@ router.post("/", async (req: express.Request, res: express.Response) => {
|
|||||||
content.destroy();
|
content.destroy();
|
||||||
}
|
}
|
||||||
handleError(error, res);
|
handleError(error, res);
|
||||||
|
if (res.headersSent && !res.writableEnded) res.destroy();
|
||||||
|
anonymizer.destroy();
|
||||||
}
|
}
|
||||||
content
|
content
|
||||||
.on("error", handleStreamError)
|
.on("error", handleStreamError)
|
||||||
|
|||||||
@@ -232,6 +232,21 @@ describe("production regressions", function () {
|
|||||||
expect(res.headers["Content-Security-Policy"]).to.include("sandbox");
|
expect(res.headers["Content-Security-Policy"]).to.include("sandbox");
|
||||||
expect(res.headers["Content-Security-Policy"]).not.to.include("allow-same-origin");
|
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 () {
|
it("keeps a conference eligible for retry when repository expiration fails", async function () {
|
||||||
const Conference = require("../src/core/Conference").default;
|
const Conference = require("../src/core/Conference").default;
|
||||||
const model = { status: "ready", save: async () => {} };
|
const model = { status: "ready", save: async () => {} };
|
||||||
|
|||||||
Reference in New Issue
Block a user