forked from jappel/leistungsbilanz-ts
Fix crash handling and log noise in logging feature
Review of the logging work from the previous commit turned up a real correctness issue: the uncaughtException/unhandledRejection handlers logged the error but let the process keep running, which silently disabled Node's default crash-on-fatal-error behavior and could leave a zombie process serving broken requests instead of restarting. Both processes now log and then exit(1); restart: unless-stopped is added to both services so Docker actually brings them back up. Also: harden the logger against JSON.stringify throwing on non-serializable meta, log aborted (closed-before-finished) requests in the API access log, and stop the Next.js proxy from logging the Docker healthcheck's request to "/" every few seconds so real navigation events aren't drowned out. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
ea3c02cd6b
commit
fa96be2d42
6 changed files with 49 additions and 15 deletions
|
|
@ -31,6 +31,15 @@ app.use((req, res, next) => {
|
|||
else if (res.statusCode >= 400) logger.warn("request completed", meta);
|
||||
else logger.info("request completed", meta);
|
||||
});
|
||||
res.on("close", () => {
|
||||
if (!res.writableEnded) {
|
||||
logger.warn("request aborted before response finished", {
|
||||
method: req.method,
|
||||
path: req.originalUrl,
|
||||
durationMs: Date.now() - startedAt,
|
||||
});
|
||||
}
|
||||
});
|
||||
next();
|
||||
});
|
||||
|
||||
|
|
@ -46,11 +55,13 @@ app.use("/api/project-devices", projectDeviceRouter);
|
|||
app.use(errorMiddleware);
|
||||
|
||||
process.on("uncaughtException", (error) => {
|
||||
logger.error("uncaught exception", toErrorMeta(error));
|
||||
logger.error("uncaught exception, exiting", toErrorMeta(error));
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on("unhandledRejection", (reason) => {
|
||||
logger.error("unhandled rejection", toErrorMeta(reason));
|
||||
logger.error("unhandled rejection, exiting", toErrorMeta(reason));
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on("SIGTERM", () => logger.info("received SIGTERM"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue