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

Commit dcf98326 by K.J. Valencik Committed by Mick Hansen

Fix MSSQL disconnect handling (#5968)

1 parent a20aa12b
# Future
- [FIXED] Pass ResourceLock instead of raw connection in MSSQL disconnect handling
# 3.23.2
- [FIXED] Type validation now works with non-strings due to updated validator@5.0.0 [#5861](https://github.com/sequelize/sequelize/pull/5861)
- [FIXED] Improved offset and limit support for SQL server 2008 [#5616](https://github.com/sequelize/sequelize/pull/5616)
......
......@@ -65,12 +65,13 @@ ConnectionManager.prototype.connect = function(config) {
});
}
var connection = new self.lib.Connection(connectionConfig);
var connection = new self.lib.Connection(connectionConfig)
, connectionLock = new ResourceLock(connection);
connection.lib = self.lib;
connection.on('connect', function(err) {
if (!err) {
resolve(new ResourceLock(connection));
resolve(connectionLock);
return;
}
......@@ -115,7 +116,7 @@ ConnectionManager.prototype.connect = function(config) {
switch (err.code) {
case 'ESOCKET':
case 'ECONNRESET':
self.pool.destroy(connection);
self.pool.destroy(connectionLock);
}
});
}
......
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, Support = require('../../support')
, dialect = Support.getTestDialect();
if (dialect.match(/^mssql/)) {
describe('[MSSQL Specific] Query Queue', function () {
it('should work with handleDisconnects', function() {
var sequelize = Support.createSequelizeInstance({pool: {min: 1, max: 1, idle: 5000}})
, cm = sequelize.connectionManager
, conn;
return sequelize.sync()
.then(function() {
return cm.getConnection();
})
.then(function(connection) {
// Save current connection
conn = connection;
// simulate a unexpected end
connection.unwrap().emit('error', {code: 'ECONNRESET'});
})
.then(function() {
return cm.releaseConnection(conn);
})
.then(function() {
// Get next available connection
return cm.getConnection();
})
.then(function(connection) {
expect(conn).to.not.be.equal(connection);
expect(cm.validate(conn)).to.not.be.ok;
return cm.releaseConnection(connection);
});
});
});
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!