Skip to content

Commit

Permalink
Support Node.js 10.x
Browse files Browse the repository at this point in the history
fixes #2003
fixes #2024
closes #2026
fixes #2034
  • Loading branch information
coreyfarrell authored and dougwilson committed Jun 21, 2018
1 parent 2913d47 commit 55265b8
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -14,6 +14,7 @@ node_js:
- "7.10"
- "8.11"
- "9.8"
- "10.3"
env:
global:
# Necessary to build Node.js 0.6 on Travis CI images
Expand Down
1 change: 1 addition & 0 deletions Changes.md
Expand Up @@ -10,6 +10,7 @@ you spot any mistakes.
* Add new error codes up to MySQL 5.7.21
* Include connection ID in debug output
* Support Node.js 9.x
* Support Node.js 10.x #2003 #2024 #2026 #2034
* Update Amazon RDS SSL certificates
* Update `bignumber.js` to 4.1.0
* Update `readable-stream` to 2.3.6
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Expand Up @@ -18,6 +18,7 @@ environment:
- nodejs_version: "7.10"
- nodejs_version: "8.11"
- nodejs_version: "9.8"
- nodejs_version: "10.3"

services:
- mysql
Expand Down
14 changes: 6 additions & 8 deletions lib/protocol/Protocol.js
@@ -1,7 +1,6 @@
var Parser = require('./Parser');
var Sequences = require('./sequences');
var Packets = require('./packets');
var Timers = require('timers');
var Stream = require('stream').Stream;
var Util = require('util');
var PacketWriter = require('./PacketWriter');
Expand Down Expand Up @@ -154,7 +153,7 @@ Protocol.prototype._enqueue = function(sequence) {
self._delegateError(err, sequence);
})
.on('packet', function(packet) {
Timers.active(sequence);
sequence._timer.active();
self._emitPacket(packet);
})
.on('end', function() {
Expand All @@ -170,7 +169,7 @@ Protocol.prototype._enqueue = function(sequence) {
self._delegateError(err, sequence);
})
.on('start-tls', function() {
Timers.active(sequence);
sequence._timer.active();
self._connection._startTLS(function(err) {
if (err) {
// SSL negotiation error are fatal
Expand All @@ -180,7 +179,7 @@ Protocol.prototype._enqueue = function(sequence) {
return;
}

Timers.active(sequence);
sequence._timer.active();
sequence._tlsUpgradeCompleteHandler();
});
});
Expand Down Expand Up @@ -265,7 +264,7 @@ Protocol.prototype._parsePacket = function() {
this._handshakeInitializationPacket = packet;
}

Timers.active(sequence);
sequence._timer.active();

if (!sequence[packetName]) {
var err = new Error('Received packet in the wrong sequence.');
Expand Down Expand Up @@ -322,7 +321,7 @@ Protocol.prototype._determinePacket = function(sequence) {
};

Protocol.prototype._dequeue = function(sequence) {
Timers.unenroll(sequence);
sequence._timer.stop();

// No point in advancing the queue, we are dead
if (this._fatalError) {
Expand All @@ -344,8 +343,7 @@ Protocol.prototype._dequeue = function(sequence) {

Protocol.prototype._startSequence = function(sequence) {
if (sequence._timeout > 0 && isFinite(sequence._timeout)) {
Timers.enroll(sequence, sequence._timeout);
Timers.active(sequence);
sequence._timer.start(sequence._timeout);
}

if (sequence.constructor === Sequences.ChangeUser) {
Expand Down
33 changes: 33 additions & 0 deletions lib/protocol/Timer.js
@@ -0,0 +1,33 @@
var Timers = require('timers');

module.exports = Timer;
function Timer(object) {
this._object = object;
this._timeout = null;
}

Timer.prototype.active = function active() {
if (this._timeout) {
if (this._timeout.refresh) {
this._timeout.refresh();
} else {
Timers.active(this._timeout);
}
}
};

Timer.prototype.start = function start(msecs) {
this.stop();
this._timeout = Timers.setTimeout(this._onTimeout.bind(this), msecs);
};

Timer.prototype.stop = function stop() {
if (this._timeout) {
Timers.clearTimeout(this._timeout);
this._timeout = null;
}
};

Timer.prototype._onTimeout = function _onTimeout() {
return this._object._onTimeout();
};
9 changes: 2 additions & 7 deletions lib/protocol/sequences/Sequence.js
Expand Up @@ -2,6 +2,7 @@ var Util = require('util');
var EventEmitter = require('events').EventEmitter;
var Packets = require('../packets');
var ErrorConstants = require('../constants/errors');
var Timer = require('../Timer');

// istanbul ignore next: Node.js < 0.10 not covered
var listenerCount = EventEmitter.listenerCount
Expand All @@ -25,13 +26,7 @@ function Sequence(options, callback) {
this._callSite = null;
this._ended = false;
this._timeout = options.timeout;

// For Timers
this._idleNext = null;
this._idlePrev = null;
this._idleStart = null;
this._idleTimeout = -1;
this._repeat = null;
this._timer = new Timer(this);
}

Sequence.determinePacket = function(byte) {
Expand Down

0 comments on commit 55265b8

Please sign in to comment.