mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 17:13:33 +01:00
fix(logging): tell our cancellations from upstream resets, keep codes, catch cut bodies
- A request we destroy ourselves is ABORT_ERR, not ECONNRESET, and a fetch abort is ABORT_ERR rather than upstream_error. - undici and DNS codes the schema lacks (UND_ERR_SOCKET, EAI_AGAIN, ...) fold into the closest kept code, so a failure always has one. - node:http records are written when the body ends: a stream cut after its headers logs ECONNRESET with its status instead of a plain 200. - Successful storage reads log at debug to keep info volume down. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7c9e803fbd
commit
c9342e4b7d
2 files changed
+96
-16
No files matched your search
@@ -6,7 +6,7 @@ const { Agent } = require("undici");
|
||||
const got = require("got");
|
||||
require("ts-node/register/transpile-only");
|
||||
const { logContext } = require("../src/core/log-context");
|
||||
const { installExternalRequestLogging, githubEndpoint } = require("../src/core/external-request-logging");
|
||||
const { installExternalRequestLogging, githubEndpoint, externalErrorCode } = require("../src/core/external-request-logging");
|
||||
|
||||
const localAgent = new http.Agent({ lookup: (host, options, callback) => lookup(host, options, callback) });
|
||||
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
@@ -41,6 +41,9 @@ describe("external request logging", function () {
|
||||
server = http.createServer((req, res) => {
|
||||
req.resume();
|
||||
if (req.url.startsWith("/login/oauth")) { res.writeHead(200, { "content-type": "application/json" }); res.end("{}"); return; }
|
||||
if (req.url.startsWith("/slow")) return; // never answers
|
||||
if (req.url.startsWith("/reset")) { req.socket.destroy(); return; }
|
||||
if (req.url.startsWith("/cut")) { res.writeHead(200, { "content-length": "100" }); res.write("partial"); setTimeout(() => req.socket.destroy(), 20); return; }
|
||||
res.writeHead(404, { "content-type": "application/json" });
|
||||
res.end(JSON.stringify({ message: "Not Found" }));
|
||||
});
|
||||
@@ -124,6 +127,36 @@ describe("external request logging", function () {
|
||||
assert.equal(records[0].upstreamEndpoint, undefined);
|
||||
});
|
||||
|
||||
it("logs our own cancellation as ABORT_ERR, not a reset by GitHub", async () => {
|
||||
const records = await captureLogs(async () => {
|
||||
const stream = got.stream(`http://api.github.com:${port}/slow`, { agent: { http: localAgent }, retry: 0 });
|
||||
stream.on("error", () => {});
|
||||
await wait(50);
|
||||
stream.destroy();
|
||||
});
|
||||
assert.equal(records.length, 1, JSON.stringify(records));
|
||||
assert.equal(records[0].errorCode, "ABORT_ERR");
|
||||
});
|
||||
|
||||
it("keeps a code for undici socket errors", async () => {
|
||||
const records = await captureLogs(() => globalThis.fetch(`http://api.github.com:${port}/reset`,
|
||||
{ dispatcher: new Agent({ connect: { lookup } }) }).catch(() => undefined));
|
||||
assert.equal(records.length, 1, JSON.stringify(records));
|
||||
assert.equal(records[0].errorCode, "ECONNRESET");
|
||||
assert.equal(externalErrorCode({ code: "UND_ERR_HEADERS_TIMEOUT" }), "ETIMEDOUT");
|
||||
assert.equal(externalErrorCode({ code: "EAI_AGAIN" }), "ENOTFOUND");
|
||||
assert.equal(externalErrorCode({ code: "SOMETHING_NEW" }), "upstream_error");
|
||||
assert.equal(externalErrorCode({ name: "AbortError" }), "ABORT_ERR");
|
||||
});
|
||||
|
||||
it("reports a body cut after its headers as a failure, not a 200", async () => {
|
||||
const records = await captureLogs(() => got(`http://codeload.github.com:${port}/cut`,
|
||||
{ agent: { http: localAgent }, retry: 0 }).catch(() => undefined));
|
||||
assert.equal(records.length, 1, JSON.stringify(records));
|
||||
assert.equal(records[0].upstreamStatus, 200);
|
||||
assert.equal(records[0].errorCode, "ECONNRESET");
|
||||
});
|
||||
|
||||
it("skips internal hops such as the streamer", async () => {
|
||||
const records = await captureLogs(async () => {
|
||||
await got(`http://127.0.0.1:${port}/api/file`, { throwHttpErrors: false, retry: 0 });
|
||||
|
||||
Reference in new issue
Block a user