不要怂,就是干,撸起袖子干!

Commit ece0d9ef by Ruben Bridgewater

Fix unhandled rejections if an error occurs in a transaction that was just committed

1 parent 7c9d1d7b
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
- [BUG] fix showIndexQuery so appropriate indexes are returned when a schema is used - [BUG] fix showIndexQuery so appropriate indexes are returned when a schema is used
- [BUG] Fix addIndexQuery error when the model has a schema - [BUG] Fix addIndexQuery error when the model has a schema
- [BUG] Fix app crash in sqlite while running in special unique constraint errors [3730](https://github.com/sequelize/sequelize/pull/3730) - [BUG] Fix app crash in sqlite while running in special unique constraint errors [3730](https://github.com/sequelize/sequelize/pull/3730)
- [BUG] Fix trying to roll back a comitted transaction if an error occured while comitting resulting in an unhandled rejection [3726](https://github.com/sequelize/sequelize/pull/3726)
# 2.1.3 # 2.1.3
- [BUG] Fix regression introduced in 2.1.2: updatedAt not set anymore [3667](https://github.com/sequelize/sequelize/pull/3667) - [BUG] Fix regression introduced in 2.1.2: updatedAt not set anymore [3667](https://github.com/sequelize/sequelize/pull/3667)
......
...@@ -1149,9 +1149,13 @@ module.exports = (function() { ...@@ -1149,9 +1149,13 @@ module.exports = (function() {
}); });
}); });
}).catch(function(err) { }).catch(function(err) {
transaction.rollback().finally(function () { if (transaction.finished === 'commit') {
reject(err); reject(err);
}); } else {
transaction.rollback().finally(function () {
reject(err);
});
}
}); });
}; };
......
...@@ -73,6 +73,30 @@ describe(Support.getTestDialectTeaser('Transaction'), function() { ...@@ -73,6 +73,30 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
expect(t.finished).to.be.equal('rollback'); expect(t.finished).to.be.equal('rollback');
}); });
}); });
if (dialect === 'postgres' || dialect === 'mssql') {
it('do not rollback if already committed', function() {
var SumSumSum = this.sequelize.define('transaction', {
value: {
type: Support.Sequelize.DECIMAL(10, 3),
field: 'value'
}
})
, transTest = function (val) {
return self.sequelize.transaction({isolationLevel: 'SERIALIZABLE'}, function(t) {
return SumSumSum.sum('value', {transaction: t}).then(function (balance) {
return SumSumSum.create({value: -val}, {transaction: t});
});
});
}
, self = this;
return SumSumSum.sync({force: true}).then(function () {
return (expect(Promise.join(transTest(80), transTest(80))).to.eventually.be.rejectedWith('could not serialize access due to read/write dependencies among transactions'));
});
});
}
}); });
it('does not allow queries after commit', function() { it('does not allow queries after commit', function() {
......
...@@ -17,7 +17,12 @@ chai.config.includeStack = true; ...@@ -17,7 +17,12 @@ chai.config.includeStack = true;
chai.should(); chai.should();
// Make sure errors get thrown when testing // Make sure errors get thrown when testing
process.on('uncaughtException', function(e, promise) {
console.error('An unhandled exception occured:');
throw e;
});
Sequelize.Promise.onPossiblyUnhandledRejection(function(e, promise) { Sequelize.Promise.onPossiblyUnhandledRejection(function(e, promise) {
console.error('An unhandled rejection occured:');
throw e; throw e;
}); });
Sequelize.Promise.longStackTraces(); Sequelize.Promise.longStackTraces();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!