-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Open
Description
Summary
The file node's append mode can have stale error handler references when the write stream is reused across multiple messages.
Problem
In append mode with static filenames, the write stream is kept open and reused. The error handler is set up once but references the msg and done from the first write. If an error occurs during a later write, the wrong message context is used.
Severity
MEDIUM - Can cause incorrect error reporting or double done() calls when write errors occur.
Proposed Fix
Add per-write error handling with a writeDone flag:
var writeDone = false;
var handleWriteError = function(err) {
if (!writeDone) {
writeDone = true;
node.wstream.removeListener('error', handleWriteError);
node.error(RED._("file.errors.appendfail",{error:err.toString()}),msg);
done();
}
};
node.wstream.on('error', handleWriteError);
node.wstream.write(buf, function() {
if (!writeDone) {
writeDone = true;
node.wstream.removeListener('error', handleWriteError);
nodeSend(msg);
done();
}
});Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels