From 4904867c3b11f895b193a0212c1479b5861e450b Mon Sep 17 00:00:00 2001 From: bain Date: Mon, 16 Sep 2024 22:34:09 +0200 Subject: [PATCH] destroy streams on client abort --- server/routes/upload.js | 4 ++++ server/routes/ws.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/server/routes/upload.js b/server/routes/upload.js index 023b83a9..86132371 100644 --- a/server/routes/upload.js +++ b/server/routes/upload.js @@ -25,6 +25,10 @@ module.exports = async function(req, res) { try { const limiter = new Limiter(encryptedSize(config.max_file_size)); const fileStream = req.pipe(limiter); + + // .pipe() does not propagate errors correctly... + req.on('error', err => fileStream.destroy(err)); + //this hasn't been updated to expiration time setting yet //if you want to fallback to this code add this await storage.set(newId, fileStream, meta, config.default_expire_seconds); diff --git a/server/routes/ws.js b/server/routes/ws.js index 17e257fd..91a2406f 100644 --- a/server/routes/ws.js +++ b/server/routes/ws.js @@ -15,7 +15,7 @@ module.exports = function(ws, req) { ws.on('close', e => { if (e !== 1000 && fileStream !== undefined) { - fileStream.destroy(); + fileStream.destroy(new Error('ws closed with error')); } });