Skip to content

Commit

Permalink
fix: remove close handler on finish
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Nov 21, 2020
1 parent bcced0b commit 4ec7835
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/middlewares/response-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ export const responseLog = (): HandleFunction => {
// items shared between the request and response of just one cycle
const cycle: Cycle = {
log: getLogger(),
time: process.hrtime()
time: process.hrtime(),
};
res.on("finish", () => logRes(req, res, cycle));
res.on("close", () => logClose(req, res, cycle));
const handleClose = () => logClose(req, res, cycle);
res.on("finish", () => {
logRes(req, res, cycle);
res.removeListener("close", handleClose);
});
res.on("close", handleClose);

next();
};
Expand Down

0 comments on commit 4ec7835

Please sign in to comment.