Skip to content

Commit

Permalink
[FIX #367] tls.connect callback performed a flushPending which didn't…
Browse files Browse the repository at this point in the history
… strip subs. (#368)
  • Loading branch information
aricart authored Aug 7, 2020
1 parent 71f3667 commit 0a430ab
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
6 changes: 2 additions & 4 deletions lib/nats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
42 changes: 36 additions & 6 deletions test/dsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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)
})
})
})

0 comments on commit 0a430ab

Please sign in to comment.