diff --git a/lib/network/http/server.js b/lib/network/http/server.js index acd86c445..98cdb68d4 100644 --- a/lib/network/http/server.js +++ b/lib/network/http/server.js @@ -351,6 +351,8 @@ class Server { error: err.stack || err, address: sock.address(), }); + // socket is not systematically destroyed + sock.destroy(); } /** diff --git a/lib/storage/data/file/DataFileStore.js b/lib/storage/data/file/DataFileStore.js index 256279991..677997dd4 100644 --- a/lib/storage/data/file/DataFileStore.js +++ b/lib/storage/data/file/DataFileStore.js @@ -199,6 +199,15 @@ class DataFileStore { return cbOnce(errors.InternalError.customizeDescription( `read stream error: ${err.code}`)); }); + dataStream.on('close', () => { + // this means the underlying socket has been closed + log.debug('Client closed socket while streaming', + { method: 'put', key, filePath }); + // destroying the write stream forces a close(fd) + fileStream.destroy(); + // we need to unlink the file ourselves + fs.unlinkSync(filePath); + }); return undefined; }); }