Skip to content

Commit

Permalink
fix: remove close listener on graceful end (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
glebec authored May 31, 2018
1 parent 43da253 commit b831dfb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/volleyball.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ function Volleyball() {
time: process.hrtime()
};
logReq(req, cycle);
res.on('finish', function () {
return logRes(res, cycle);
});
res.on('close', function () {

var handleUnexpectedClose = function handleUnexpectedClose() {
return logClose(res, cycle);
};

res.on('finish', function () {
logRes(res, cycle);
res.removeListener('close', handleUnexpectedClose);
});
res.on('close', handleUnexpectedClose);
next();
} // factory method which does not expose any of the library internals

Expand Down
9 changes: 7 additions & 2 deletions src/volleyball.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ function Volleyball(config = {}) {
}

logReq(req, cycle)
res.on('finish', () => logRes(res, cycle))
res.on('close', () => logClose(res, cycle))

const handleUnexpectedClose = () => logClose(res, cycle)
res.on('finish', () => {
logRes(res, cycle)
res.removeListener('close', handleUnexpectedClose)
})
res.on('close', handleUnexpectedClose)

next()
}
Expand Down

0 comments on commit b831dfb

Please sign in to comment.