0

I'm getting the "Error: Trying to open unclosed connection," but I don't believe it's due to a db issue... and that's why I'm stumped. Most solutions to this error, reference db connection issues.

My goal here is execute an external process. If the process closes with anything other than exit code 0, I want to email an alert for example.

I was using the child.on('close', function(code).... to get the exit value from the external process (coming back as "code") So if code !=0 I want to do something... maybe rerun the test... maybe call a different method that sends an email, etc.

Each time I attempt to call a method, from within child.on('close'), I get the error "Trying to open unclosed connection." Which is why I'm also handling the save action in the same block.

Code Sample:

var spawn = require('child_process').spawn,
        child = spawn('sipp', ['-s', dnis,server, '-sn', scenario, '-m', '1','-i','127.0.0.1','-recv_timeout','1000']);
}
child.on('close',function(code){
     if(code != 0){
         Call().emailAlert(dnis, server, scenario, type, carrier);
     }        
        var TestResults = mongoose.model('test_results', TestResultsSchema);
        // Saving results to MongoDB
        var result = new TestResults({
            testType: type,
            dnis: dnis,
            server: server,
            result: code,
            carrier: carrier,
            date: Date.now()
        });
        result.save(function (err) {if (!err) {console.log ('Successful Save!')}
        else{console.log(err)}});
});

};

If I remove:

if(code != 0){
     Call().emailAlert(dnis, server, scenario, type, carrier);
 }   

The error goes away. What's the best way for me to capture the exit code of the process, and based on it, make a call to a different method (i.e. to email an alert) in Node.js?

continuousqa
  • 508
  • 4
  • 14

1 Answers1

0

I guess I was wrong. I changed the mongoose.connect to mongoose.createConnection and this specific error went away... but unfortunately I'm left with more errors. I'll open up the main question in a different topic.

continuousqa
  • 508
  • 4
  • 14