Comparing version 0.2.5 to 0.2.6
@@ -61,16 +61,11 @@ /* vim: set expandtab tabstop=2 shiftwidth=2 foldmethod=marker: */ | ||
Connection.prototype.close = function () { | ||
Connection.prototype.close = function (cb) { | ||
if (this._flag < 0) { | ||
return; | ||
} | ||
this._flag = -1; | ||
var _self = this; | ||
var timer = setTimeout(function () { | ||
_self._conn.destroy(); | ||
}, 10); | ||
this._conn.end(function () { | ||
clearTimeout(timer); | ||
cb && cb(); | ||
}); | ||
@@ -92,12 +87,14 @@ }; | ||
_self._conn._implyConnect(); | ||
_self._conn._socket.setTimeout(_self._socketTimeout); | ||
_self._conn._socket.removeAllListeners('timeout'); | ||
if (_self._flag > 0) { | ||
_self._conn._implyConnect(); | ||
_self._conn._socket.setTimeout(_self._socketTimeout); | ||
_self._conn._socket.removeAllListeners('timeout'); | ||
_self._conn._socket.once('timeout', function () { | ||
var e = _self._error('SocketTimeout', 'Mysql socket timeout after ' + _self._socketTimeout + ' ms'); | ||
e.fatal = true; | ||
callback(e); | ||
callback = noop; | ||
}); | ||
_self._conn._socket.once('timeout', function () { | ||
var e = _self._error('SocketTimeout', 'Mysql socket timeout after ' + _self._socketTimeout + ' ms.'); | ||
e.fatal = true; | ||
callback(e); | ||
callback = noop; | ||
}); | ||
} | ||
@@ -104,0 +101,0 @@ if (!timeout || isNaN(+timeout) || timeout < 1) { |
@@ -105,8 +105,16 @@ /* vim: set expandtab tabstop=2 shiftwidth=2 foldmethod=marker: */ | ||
var _remove = function (c, o) { | ||
if (!c) { | ||
return; | ||
} | ||
var i = conns.indexOf(c); | ||
c.removeAllListeners('error'); | ||
c.close(); | ||
c = null; | ||
if (i < 0) { | ||
return; | ||
} | ||
c.close(); | ||
c = null; | ||
conns.splice(i, 1); | ||
@@ -113,0 +121,0 @@ i = o._stack.indexOf(i); |
{ | ||
"name": "easymysql", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"author": "Aleafs Zhang (zhangxc83@gmail.com)", | ||
@@ -5,0 +5,0 @@ "contributors": [], |
@@ -64,11 +64,11 @@ [![Build Status](https://secure.travis-ci.org/aleafs/easymysql.png?branch=master)](http://travis-ci.org/aleafs/easymysql) | ||
project: easymysql | ||
commits: 146 | ||
commits: 161 | ||
files : 16 | ||
authors: | ||
130 aleafs 89.0% | ||
11 zhaolei 7.5% | ||
4 tangyao 2.7% | ||
1 紫胤 0.7% | ||
135 aleafs 83.9% | ||
21 zhaolei 13.0% | ||
4 tangyao 2.5% | ||
1 紫胤 0.6% | ||
``` | ||
``` | ||
## License | ||
@@ -75,0 +75,0 @@ |
@@ -191,3 +191,75 @@ /* vim: set expandtab tabstop=2 shiftwidth=2 foldmethod=marker: */ | ||
describe('a error lost connection case', function () { | ||
it('should_return_error_when_query_after_the_close_method_called', function (done) { | ||
var _me = Connection.create(Common.config); | ||
_me.on('error', function (e) {}); | ||
var _count = 5; | ||
var errors = []; | ||
var _back = function (err, res) { | ||
if (err) { | ||
err.code.should.eql('PROTOCOL_ENQUEUE_AFTER_QUIT'); | ||
errors.push(err); | ||
} | ||
_count --; | ||
if(_count <= 0) { | ||
errors.length.should.eql(3); | ||
done(); | ||
} | ||
}; | ||
(function x() { | ||
_me.query('SELECT SLEEP(0.2)', 0, function (e, r) { | ||
_back(e, r); | ||
if (3 === _count) { | ||
_me.close(); | ||
} | ||
if (_count) { | ||
x(); | ||
} | ||
}); | ||
})(); | ||
}); | ||
it('should_socket_timeout_then_close_not_hang_up', function (done) { | ||
var _config = Common.extend({ | ||
sockettimeout : 10 | ||
}); | ||
var _me = Connection.create(_config); | ||
_me.on('error', function (e) {}); | ||
var _count = 5; | ||
var errors = {}; | ||
var _back = function (err, res) { | ||
if (err) { | ||
if (errors[err.name]) { | ||
errors[err.name] ++; | ||
} else { | ||
errors[err.name] = 1; | ||
} | ||
} | ||
_count --; | ||
if(_count <= 0) { | ||
errors.MysqlError.should.eql(3); | ||
errors.SocketTimeout.should.eql(2); | ||
done(); | ||
} | ||
}; | ||
(function x() { | ||
_me.query('SELECT SLEEP(0.2)', 0, function (e, r) { | ||
_back(e, r); | ||
if (3 === _count) { | ||
_me.close(); | ||
} | ||
if (_count) { | ||
x(); | ||
} | ||
}); | ||
})(); | ||
}); | ||
}); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39717
1244