Files
anonymous_github/src/streamer/index.ts
T
Thomas DurieuxandClaude Opus 5.5 0a0b579c13 fix(logging): keep uncoded streamer 4xx replies on the Errors page
An uncoded 4xx comes from something in front of the streamer (body-size
limit, ingress, wrong entrypoint), so it is now streamer_unexpected_response
(502, error) rather than an info-level file_not_found. The streamer's
catch-all route gets its own code so a misrouted call logs at warn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 11:47:06 +00:00

68 lines
2.1 KiB
TypeScript

import { installFatalErrorLogging } from "../core/process-monitoring";
import { config as dotenv } from "dotenv";
dotenv();
import * as express from "express";
import * as compression from "compression";
import config from "../config";
import router from "./route";
import { handleError } from "../server/routes/route-utils";
import AnonymousError from "../core/AnonymousError";
import { createLogger, serializeError } from "../core/logger";
import { connect } from "../server/database";
import { startTemporaryStorageMaintenance } from "../core/temporary-storage";
import { monitorRequests } from "../core/request-monitoring";
import { startPerformanceMonitoring } from "../core/performance-monitoring";
import { getAnonymizationPoolStats } from "../core/anonymization-pool";
const logger = createLogger("streamer");
installFatalErrorLogging("streamer");
const app = express();
app.use(monitorRequests("streamer"));
app.use(express.json());
app.use(
compression({
filter: (req, res) => {
// The streamer serves file blobs that are often binary (images,
// archives) and can be very large. Compressing them holds zlib
// buffers per response that pile up under concurrent load.
if (req.path === "/api" && req.method === "POST") return false;
return compression.filter(req, res);
},
})
);
app.use("/api", router);
app.get("/healthcheck", async (_, res) => {
res.json({ status: "ok" });
});
app.all("/{*path}", (req, res) => {
handleError(
// Callers only use known routes; reaching here is a misconfiguration.
new AnonymousError("streamer_route_not_found", {
httpStatus: 404,
url: req.originalUrl,
}),
res,
req
);
});
async function start() {
startPerformanceMonitoring("streamer", getAnonymizationPoolStats);
await connect({ appName: "Anonymous GitHub Streamer", maxPoolSize: 10, minPoolSize: 0 });
await startTemporaryStorageMaintenance();
app.listen(config.PORT, (error?: Error) => {
if (error) throw error;
logger.info("streamer started", { port: config.PORT });
});
}
void start().catch(error => {
logger.error("streamer startup failed", serializeError(error));
process.exit(1);
});