Skip to content

Commit 0902d14

Browse files
Vratislavbrianc
authored andcommitted
fix: end stream connection
1 parent 860928e commit 0902d14

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

lib/connection.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ Connection.prototype.end = function () {
309309
// 0x58 = 'X'
310310
this.writer.add(emptyBuffer)
311311
this._ending = true
312-
return this.stream.write(END_BUFFER)
312+
return this.stream.write(END_BUFFER, () => {
313+
this.stream.end()
314+
})
313315
}
314316

315317
Connection.prototype.close = function (msg, more) {

test/unit/connection/outbound-sending-tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ test('sends end command', function () {
183183
con.end()
184184
var expected = Buffer.from([0x58, 0, 0, 0, 4])
185185
assert.received(stream, expected)
186+
assert.equal(stream.closed, true)
186187
})
187188

188189
test('sends describe command', function () {

test/unit/test-helper.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ helper.sys.inherits(MemoryStream, EventEmitter)
1313

1414
var p = MemoryStream.prototype
1515

16-
p.write = function (packet) {
16+
p.write = function (packet, cb) {
1717
this.packets.push(packet)
18+
if(cb){
19+
cb();
20+
}
1821
}
1922

20-
p.setKeepAlive = function () {}
23+
p.end = function() {
24+
p.closed = true;
25+
}
2126

27+
p.setKeepAlive = function () {}
28+
p.closed = false;
2229
p.writable = true
2330

2431
const createClient = function () {

0 commit comments

Comments
 (0)