From 6dcae6d988b7a5dfd59b18db173e61cdf3d57f8a Mon Sep 17 00:00:00 2001 From: nielm Date: Thu, 4 Nov 2021 18:07:40 +0100 Subject: [PATCH] Ensure stream is closed if a read error occurs --- cloudrun-malware-scanner/server.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cloudrun-malware-scanner/server.js b/cloudrun-malware-scanner/server.js index 422e401..0d2d71d 100644 --- a/cloudrun-malware-scanner/server.js +++ b/cloudrun-malware-scanner/server.js @@ -109,7 +109,12 @@ app.post('/', async (req, res) => { file.size} bytes) scanning with clam ${clamdVersion}`); const startTime = Date.now(); const readStream = await gcsFile.createReadStream(); - const result = await scanner.scanStream(readStream); + let result; + try { + result = await scanner.scanStream(readStream); + } finally { + readStream.destroy(); + } const scanDuration = Date.now() - startTime; if (clamd.isCleanReply(result)) {