Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node application crashing in production while doing transaction.begin intermittently. #521

Closed
sanjeev2315 opened this issue Aug 28, 2017 · 1 comment

Comments

@sanjeev2315
Copy link

sanjeev2315 commented Aug 28, 2017

We are using node greater than 4.0 version with node-mssql. I have enabled try catch, promise then-catch pattern, as well as handled unhandled rejection and uncaught errors in my node server with proper logging. But we are seeing that server got crashed 2-3 times everyday when users are performing operations on front end. From the logs it shows me the log before transaction.begin statement but not the next log after that line. Try catch and Promise then catch as well as other handlers not logging it and not capturing it. Its like a very serious matter. Below is the code snippet
`
var connection = new sql.Connection({
user: '...',
password: '...',
server: 'localhost',
database: '...'
});

connection.connect(function(err) {
//Log1 here prints
try{
var transaction = new sql.Transaction(/* [connection] */);
//Log2 here prints
transaction.begin(function(err) {
//Log3 here does not print when we get the isue
// ... error checks

var rolledBack = false;

transaction.on('rollback', function(aborted) {
    // emited with aborted === true 
    
    rolledBack = true;
});
}catch(err){
//Log 4 here does not prints

}).then(..)
.catch(err){
//Log5 here does not prints
}

//server.js(main file)

....
....
.
.
process
.on('unhandledRejection', (reason, p) => {
//Log6 It does not prints
console.error(reason, 'Unhandled Rejection at Promise', p);
})
.on('uncaughtException', err => {
//Log7 It does not prints
console.error(err, 'Uncaught Exception thrown');
process.exit(1);
});
app.use(function (err, req, res, next) {
//Log8 It does not prints
});
``
`

@willmorgan
Copy link
Collaborator

More recent versions of node-mssql have improved lifecycle management which I think should resolve this issue, so I'm closing it. Please upgrade to v4.2.2 (most recent at time of writing). If this doesn't improve things then please feel free to reopen.

Particularly this could have been fixed by #683.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants