fix(server): incorrect abort condition (#13100)

fix AI-308
This commit is contained in:
DarkSky
2025-07-08 18:18:25 +08:00
committed by GitHub
parent 3226a0a3fe
commit e027564d2a

View File

@@ -21,16 +21,19 @@ type SignalReturnType = {
export function getSignal(req: Request): SignalReturnType {
const controller = new AbortController();
let isAborted = true;
let hasEnded = false;
let callback: ((isAborted: boolean) => void) | undefined = undefined;
const onSocketEnd = () => {
isAborted = false;
hasEnded = true;
};
const onSocketClose = (hadError: boolean) => {
req.socket.off('end', onSocketEnd);
req.socket.off('close', onSocketClose);
const aborted = hadError || isAborted;
// NOTE: the connection is considered abnormally interrupted:
// 1. there is an error when the socket is closed.
// 2. the connection is closed directly without going through the normal end process (the client disconnects actively).
const aborted = hadError || !hasEnded;
if (aborted) {
controller.abort();
}