From 852da62ee90c296cc6f74bc89114e76158eca1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Mon, 22 Aug 2011 15:54:34 +0200 Subject: [PATCH] Fix #96 --- lib/client.js | 3 ++- test/fast/test-client.js | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/client.js b/lib/client.js index afd35d365..4888bad6a 100644 --- a/lib/client.js +++ b/lib/client.js @@ -292,7 +292,8 @@ Client.prototype._handlePacket = function(packet) { if (!this.connected) { if (packet.type != Parser.ERROR_PACKET) { this.connected = true; - this._queue[0].fn(); + + if (this._queue.length) this._queue[0].fn(); return; } diff --git a/test/fast/test-client.js b/test/fast/test-client.js index 2f4b1b6d0..a8e868ee6 100644 --- a/test/fast/test-client.js +++ b/test/fast/test-client.js @@ -3,14 +3,24 @@ var assert = require('assert'); var test = common.fastOrSlow.fast(); var Client = require(common.dir.lib + '/client'); +var client; test.before(function() { - this.client = new Client(); + client = new Client(); }); test('#format() does not manipulate params parameter', function() { var sql = '?'; var params = [1]; - this.client.format(sql, params); + client.format(sql, params); assert.equal(params.length, 1); }); + +// https://github.com/felixge/node-mysql/issues/96 +test('Timeout reconnect works with empty queue', function() { + // A non-error packet + var packet = {}; + + // This must not throw an error + client._handlePacket(packet); +});