Skip to content

Commit

Permalink
Ensure stream is closed if a read error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
nielm committed Nov 15, 2021
1 parent 0a7628d commit 6dcae6d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cloudrun-malware-scanner/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 6dcae6d

Please sign in to comment.