mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-12 08:47:40 -05:00
Remove upload temp files on every exit path
Rejected uploads (unknown system, bad key, invalid file or source list) and uploads that threw returned without deleting multer's temp file, leaking 751k files (39 GB) in the backend container since April. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -162,11 +162,6 @@ exports.upload = async function (req, res, next) {
|
||||
});
|
||||
|
||||
if (!talkgroupExists) {
|
||||
try {
|
||||
fs.unlinkSync(req.file.path);
|
||||
} catch (err) {
|
||||
console.error(`[${call.shortName}] error deleting: ${req.file.path}`);
|
||||
}
|
||||
res.status(500).send("Talkgroup does not exist, skipping.\n");
|
||||
return;
|
||||
}
|
||||
@@ -233,16 +228,19 @@ exports.upload = async function (req, res, next) {
|
||||
next();
|
||||
}
|
||||
|
||||
try {
|
||||
fs.unlinkSync(req.file.path);
|
||||
} catch (err) {
|
||||
console.warn("There was an Error deleting: " + req.file.path);
|
||||
}
|
||||
cleanupTime = Date.now();
|
||||
//console.log(`[${call.shortName}] \t Verify System: ${validateSystemTime - start_time} \t Read file: ${readFileTime - validateSystemTime} \t Upload: ${ uploadFileTime - validateSystemTime} \t Save: ${saveCallTime - uploadFileTime} \tStats: ${statsTime - saveCallTime}\tCleanup: ${cleanupTime - statsTime} \t\t Total: ${cleanupTime - start_time}`);
|
||||
} catch (error) {
|
||||
console.error("Error processing call upload: " + error);
|
||||
} finally {
|
||||
// multer has already written the temp file, so remove it on every exit path.
|
||||
if (req.file) {
|
||||
try {
|
||||
fs.unlinkSync(req.file.path);
|
||||
} catch (err) {
|
||||
console.warn("There was an Error deleting: " + req.file.path);
|
||||
}
|
||||
}
|
||||
cleanupTime = Date.now();
|
||||
const totalTime = Date.now() - start_time;
|
||||
if (totalTime > 10000) {
|
||||
console.warn(`[${req.params.shortName}] Slow Upload - Size: ${call.len} Verify System: ${validateSystemTime - start_time} Read file: ${readFileTime - validateSystemTime} Upload: ${ uploadFileTime - validateSystemTime} Save: ${saveCallTime - uploadFileTime} Stats: ${statsTime - saveCallTime} Cleanup: ${cleanupTime - statsTime} Total: ${totalTime}`);
|
||||
|
||||
Reference in New Issue
Block a user