destroy streams on client abort

This commit is contained in:
bain 2024-09-16 22:34:09 +02:00
parent f54f3ccaa2
commit 4904867c3b
Signed by: bain
GPG key ID: 31F0F25E3BED0B9B
2 changed files with 5 additions and 1 deletions

View file

@ -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);

View file

@ -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'));
}
});