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

Commit 94aa2acd by iuri aranda

Add testcase to test connection hang ups when a query is issued 100 ms after the…

… last one (right when the client connection is closing)
Also added a possible fix
1 parent 65518552
...@@ -225,9 +225,7 @@ module.exports = (function() { ...@@ -225,9 +225,7 @@ module.exports = (function() {
var disconnect = function(client) { var disconnect = function(client) {
var self = this; var self = this;
if (!this.useQueue) {
this.client = null; this.client = null;
}
client.end(function() { client.end(function() {
if (!self.useQueue) { if (!self.useQueue) {
...@@ -238,14 +236,11 @@ module.exports = (function() { ...@@ -238,14 +236,11 @@ module.exports = (function() {
var cleanup = function () { var cleanup = function () {
var retryCt = 0 var retryCt = 0
// make sure to let client finish before calling destroy // make sure to let client finish before calling destroy
if (self && self.hasQueuedItems) { if (client._queue && (client._queue.length > 0)) {
return return
} }
// needed to prevent mysql connection leak // needed to prevent mysql connection leak
client.destroy() client.destroy()
if (self && self.client) {
self.client = null
}
clearInterval(intervalObj) clearInterval(intervalObj)
} }
intervalObj = setInterval(cleanup, 10) intervalObj = setInterval(cleanup, 10)
......
...@@ -32,5 +32,26 @@ if (Support.dialectIsMySQL()) { ...@@ -32,5 +32,26 @@ if (Support.dialectIsMySQL()) {
}) })
}) })
}) })
it('accepts new queries after shutting down a connection', function(done) {
// Create a sequelize instance with pooling disabled
var sequelize = Support.createSequelizeInstance({ pool: false })
var User = sequelize.define('User', { username: DataTypes.STRING })
User.sync({force: true}).on('success', function() {
User.create({username: 'user1'}).on('success', function() {
// After 100 ms the DB connection will be disconnected for inactivity
setTimeout(function() {
// This query will be queued just after the `client.end` is executed and before its callback is called
sequelize.query('SELECT COUNT(*) AS count FROM Users').on('success', function(count) {
expect(count[0].count).to.equal(1)
done()
}).error(function(error) {
expect(error).to.not.exist
})
}, 100)
})
})
})
}) })
} }
...@@ -45,7 +45,7 @@ var Support = { ...@@ -45,7 +45,7 @@ var Support = {
var config = Config[options.dialect] var config = Config[options.dialect]
options.logging = (options.hasOwnProperty('logging') ? options.logging : false) options.logging = (options.hasOwnProperty('logging') ? options.logging : false)
options.pool = options.pool || config.pool options.pool = options.pool !== undefined ? options.pool : config.pool
var sequelizeOptions = { var sequelizeOptions = {
host: options.host || config.host, host: options.host || config.host,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!