mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 17:13:33 +01:00
fix: keep a session reply intact when the streamer reports an error
With a session cookie, express-session's res.end writes all but the last body byte and sends that byte after the Redis touch. In between, headersSent is true and writableEnded is false, so the res.destroy() that followed handleError cut the API's own 404 reply. Nginx then saw no response header and returned 502 to logged-in visitors of repos whose source is gone. Decide whether to cut the response from headersSent before handleError replies, as the zip proxy already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a4f65e7d30
commit
111870b6e2
3 files changed
+80
-3
No files matched your search
@@ -548,8 +548,12 @@ export default class AnonymizedFile {
|
||||
);
|
||||
void notifyOwnerAccessProblem(this.repository.owner.id, error, { kind: "repository", id: String(this.repository.model._id) });
|
||||
error.value = this;
|
||||
// Only a response that was already streaming body bytes must be
|
||||
// cut. handleError's own reply can be mid-write: express-session
|
||||
// holds back its last byte until the session store touch ends.
|
||||
const streaming = res.headersSent;
|
||||
handleError(error, res);
|
||||
if (res.headersSent && !res.writableEnded) res.destroy();
|
||||
if (streaming && !res.writableEnded) res.destroy();
|
||||
});
|
||||
resolve();
|
||||
return;
|
||||
|
||||
@@ -41,8 +41,9 @@ router.post(
|
||||
res
|
||||
);
|
||||
} catch (error) {
|
||||
const streaming = res.headersSent;
|
||||
handleError(error, res);
|
||||
if (res.headersSent && !res.writableEnded) res.destroy();
|
||||
if (streaming && !res.writableEnded) res.destroy();
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -121,8 +122,9 @@ router.post("/", async (req: express.Request, res: express.Response) => {
|
||||
if (!content.closed && !content.destroyed) {
|
||||
content.destroy();
|
||||
}
|
||||
const streaming = res.headersSent;
|
||||
handleError(error, res);
|
||||
if (res.headersSent && !res.writableEnded) res.destroy();
|
||||
if (streaming && !res.writableEnded) res.destroy();
|
||||
anonymizer.destroy();
|
||||
}
|
||||
content
|
||||
|
||||
Reference in new issue
Block a user