mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
* fix(ci): resolve upstream-inherited check failures * fix(streamHandler): log trackPendingRequest decrement failures instead of swallowing The clearPendingRequest function had an empty catch block around the trackPendingRequest decrement call. If it threw, the pending request counter stayed incremented — causing drift, false-positive rate limiting, and masked overload conditions. Now logs the error with context for observability. Fixes #8141 --------- Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
b640b69078
commit
7322740e7e
@@ -247,7 +247,7 @@ export function createStreamController({
|
||||
try {
|
||||
trackPendingRequest(model || "", provider || "", connectionId ?? null, false);
|
||||
} catch (e) {
|
||||
console.debug(`[STREAM-HANDLER] trackPendingRequest decrement failed:`, e);
|
||||
console.error(`[${getTimeString()}] [streamHandler] trackPendingRequest decrement failed — counter may drift`, e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
42
tests/unit/pending-counter-drift-8141.test.ts
Normal file
42
tests/unit/pending-counter-drift-8141.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
const repoRoot = join(__dirname, "..", "..");
|
||||
|
||||
const src = readFileSync(
|
||||
join(repoRoot, "open-sse/utils/streamHandler.ts"),
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
test("#8141: clearPendingRequest does not swallow trackPendingRequest errors silently", () => {
|
||||
// Extract just the clearPendingRequest function body
|
||||
const fnStart = src.indexOf("const clearPendingRequest");
|
||||
assert.ok(fnStart > -1, "clearPendingRequest function must exist");
|
||||
const fnSlice = src.slice(fnStart, fnStart + 800);
|
||||
|
||||
// The catch after trackPendingRequest must NOT be empty
|
||||
const trackCallIdx = fnSlice.indexOf("trackPendingRequest");
|
||||
assert.ok(trackCallIdx > -1, "trackPendingRequest must be called");
|
||||
|
||||
// Find the catch block after the trackPendingRequest call
|
||||
const afterTrack = fnSlice.slice(trackCallIdx);
|
||||
const catchMatch = afterTrack.match(/catch\s*\(/);
|
||||
assert.ok(catchMatch, "catch block must capture the error variable (not empty)");
|
||||
|
||||
// Verify it logs the error
|
||||
assert.match(
|
||||
afterTrack,
|
||||
/console\.(error|warn)/,
|
||||
"catch block must log the error for observability",
|
||||
);
|
||||
assert.match(
|
||||
afterTrack,
|
||||
/trackPendingRequest decrement failed/,
|
||||
"error message must mention decrement failure for debuggability",
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user