diff --git a/lib/nats.js b/lib/nats.js index 53c8e9fd..2d29ea24 100644 --- a/lib/nats.js +++ b/lib/nats.js @@ -1252,9 +1252,7 @@ Client.prototype.processInbound = function () { } try { // Refer to issue #310 - this.stream = tls.connect(tlsOpts, () => { - this.flushPending() - }) + this.stream = tls.connect(tlsOpts) } catch (error) { this.emit('error', new NatsError(OPENSSL_ERR_MSG_PREFIX + error, OPENSSL_ERR, error)) return @@ -1708,7 +1706,7 @@ Client.prototype.handledInvalidArgs = function (args) { * ommitted, even with a callback. The Subscriber Id is returned. * * @param {String} subject - * @param {Object} [opts] + * @param {Object} [options] * @param {Function} callback - callback arguments are data, reply subject (may be undefined), and subscription id * @return {Number} * @api public diff --git a/test/dsub.js b/test/dsub.js index b085727a..9c603086 100644 --- a/test/dsub.js +++ b/test/dsub.js @@ -22,25 +22,33 @@ const after = require('mocha').after const before = require('mocha').before const describe = require('mocha').describe const it = require('mocha').it +const should = require('should') describe('Double SUBS', () => { const PORT = 1922 - const flags = ['-DV'] + const TLSPORT = 2292 let server + let tlsServer // Start up our own nats-server before(done => { - server = nsc.startServer(PORT, flags, done) + const flags = ['-DV', '--tls', '--tlscert', './test/certs/server.pem', + '--tlskey', './test/certs/key.pem'] + server = nsc.startServer(PORT, ['-DV'], () => { + tlsServer = nsc.startServer(TLSPORT, flags, done) + }) }) // Shutdown our server after we are done after(done => { - nsc.stopServer(server, done) + nsc.stopServer(server, () => { + nsc.stopServer(tlsServer, done) + }) }) it('should not send multiple subscriptions on startup', done => { let subsSeen = 0 - const subRe = /(\[SUB foo \d\])+/g + const subRe = /(\[SUB foo \d])+/g // Capture log output from nats-server and check for double SUB protos. server.stderr.on('data', data => { @@ -54,9 +62,31 @@ describe('Double SUBS', () => { nc.on('connect', nc => { setTimeout(() => { nc.close() - subsSeen.should.equal(1) + should.equal(subsSeen, 1) + done() + }, 400) + }) + }) + + it('should not send multiple subscriptions on tls startup', done => { + let subsSeen = 0 + const subRe = /(\[SUB foo \d])+/g + + // Capture log output from nats-server and check for double SUB protos. + tlsServer.stderr.on('data', data => { + while (subRe.exec(data) !== null) { + subsSeen++ + } + }) + + const nc = NATS.connect({ port: TLSPORT, tls: { rejectUnauthorized: false } }) + nc.subscribe('foo') + nc.on('connect', nc => { + setTimeout(() => { + nc.close() + should.equal(subsSeen, 1) done() - }, 100) + }, 400) }) }) })