FATAL ERROR: JS Allocation failed
Problem
My script is failing when attempting to load the template, with the following error:
FATAL ERROR: JS Allocation failed - process out of memory exited with code 5
The code that I'm calling looks like this:
emailTemplates(templatesDir, function(err, template) {
winston.info("Setting up templates.", templatesDir);
if(err) {
winston.error(err);
}else{
var today = new Date().getDay();
winston.info("Found that today is ", aDays[today]);
template("notify", {
reports: [{
item: "merged",
desc: "Blah blah"
},{
item: "searched",
desc: "Blah blah"
}],
vars: Operators.BBT.mail,
day: aDays[today],
fusionAPIRan: canRunFAPI
}, function(err, html, text) {
if(err) {
winston.error(err);
}else{
winston.info("Attempting to send an email!");
smtpTransport.sendMail({
from: "Webmaster ",
to: "[email protected]",
subject: "Worker - Notification Email",
html: html
}, function(error, response){
if(error){
winston.error(error);
cb(false);
}else{
winston.info("Message sent: " + response.message + ", message id: " + response.messageId);
cb(true);
}
});
}
});
}
});
It gets as far as Found that today is xxx
and the winston.error
inside doesn't get called. What's causing that? A dodgy template perhaps?
Solution
After a lot of digging and debugging, I've managed to find the cause of this issue. I am using the node-email-templates which uses EJS to process JavaScript code within a HTML template and then email it using Nodemailer.
The problem occurs within the EJS module, specifically when trying to process variables within comments.
The code within the comment causes a crash somewhere along the line. I've reported this bug on the GitHub issues page of EJS. I'm going to attempt to fix it when I get some time at work.
Discussion
View additional discussion.