Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Always emit the close event
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Mar 29, 2020
1 parent 6391ac1 commit 18369cc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/express/idempotency.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ function cacheResponse (key, req, res) {
responseStateListener,
});
const tmpFile = path.resolve(os.tmpdir(), `${util.uuidV4()}.response`);
const responseListener = fs.createWriteStream(tmpFile);
const responseListener = fs.createWriteStream(tmpFile, {
emitClose: true,
});
const originalSocketWriter = res.socket.write.bind(res.socket);
const patchedWriter = (chunk, encoding, next) => {
responseListener.write(chunk);
Expand All @@ -54,7 +56,7 @@ function cacheResponse (key, req, res) {
responseListener.end();
}
});
responseListener.once('finish', () => {
responseListener.once('close', () => {
if (!IDEMPOTENT_RESPONSES.has(key)) {
const msg = `Could not cache the response identified by '${key}'. ` +
`Cache consistency has been damaged`;
Expand Down

0 comments on commit 18369cc

Please sign in to comment.