Skip to content

Commit 4ebdc74

Browse files
Merge changes from internal node-hdb repo for v2.26.2 patch release
Merge changes from internal node-hdb repo for v2.26.2 patch release
2 parents 1e1b72b + 10ad020 commit 4ebdc74

3 files changed

Lines changed: 86 additions & 39 deletions

File tree

lib/protocol/ResultSet.js

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,15 @@ ResultSet.prototype.resume = function resume() {
150150
};
151151

152152
ResultSet.prototype.close = function close(cb) {
153-
this.finished = true;
154-
this._running = false;
153+
if (this.closed) {
154+
if (typeof cb === 'function') {
155+
return cb();
156+
}
157+
return;
158+
}
155159
var self = this;
156-
process.nextTick(function callEmitEndAndClose() {
157-
emitEnd.call(self);
160+
emitEnd.call(self);
161+
process.nextTick(function callSendClose() {
158162
sendClose.call(self, cb);
159163
});
160164
};
@@ -297,16 +301,19 @@ function sendClose(cb) {
297301
if (err) {
298302
debug('close failed: %s', err);
299303
} else {
300-
self.closed = true;
301304
emitClose.call(self);
302305
}
303306
if (util.isFunction(cb)) {
304307
cb(err);
305308
}
306309
}
307-
this._connection.closeResultSet({
308-
resultSetId: this.id
309-
}, done);
310+
if (this._connection) {
311+
this._connection.closeResultSet({
312+
resultSetId: this.id
313+
}, done);
314+
} else if (util.isFunction(cb)) {
315+
cb();
316+
}
310317
}
311318

312319
function sendFetch() {
@@ -348,17 +355,9 @@ function handleData(data) {
348355
this.emit('data', data.buffer);
349356
}
350357

351-
if (isLast(data)) {
352-
this.finished = true;
353-
this._running = false;
354-
this.closed = isClosed(data);
355-
}
356-
357358
var self = this;
358-
if (self.finished) {
359-
process.nextTick(function callEmitEnd() {
360-
emitEnd.call(self);
361-
});
359+
if (isLast(data)) {
360+
emitEnd.call(self, isClosed(data));
362361
return;
363362
}
364363

@@ -369,22 +368,35 @@ function handleData(data) {
369368
}
370369
}
371370

372-
function emitEnd() {
371+
function emitEnd(isClosed = false) {
373372
/* jshint validthis:true */
374373
debug('emit "end"');
375-
this.emit('end');
376-
var self = this;
377-
if (this.closed) {
378-
process.nextTick(function callEmitClose() {
379-
emitClose.call(self);
380-
});
374+
var shouldEmit = !this.finished;
375+
if (!this.finished) {
376+
this.finished = true;
377+
this._running = false;
381378
}
379+
let self = this;
380+
process.nextTick(function callEmitEnd() {
381+
if (shouldEmit) {
382+
self.emit('end');
383+
}
384+
if (isClosed) {
385+
emitClose.call(self);
386+
}
387+
});
382388
}
383389

384390
function emitClose() {
385391
/* jshint validthis:true */
386392
debug('emit "close"');
387-
this.emit('close');
393+
if (!this.closed) {
394+
this.closed = true;
395+
let self = this;
396+
process.nextTick(function callEmitClose() {
397+
self.emit('close');
398+
});
399+
}
388400
}
389401

390402
function isLast(data) {

package.json

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
{
2-
"author": "Koser, Holger <holger.koser@sap.com>",
2+
"author": {
3+
"name": "SAP SE",
4+
"url": "https://www.sap.com/"
5+
},
36
"contributors": [
7+
"Albion, Jeff <jeff.albion@sap.com>",
8+
"Ian, McCurdy <ian.mccurdy@sap.com>",
9+
"He, Linjun <linjun.he@sap.com>",
10+
"Koser, Holger <holger.koser@sap.com>",
411
"Vachkov, Georgi <georgi.vachkov@sap.com>",
512
"Penev, Alexander <alexander.penev@sap.com>"
613
],
714
"name": "hdb",
815
"description": "SAP HANA Database Client for Node",
9-
"version": "2.26.1",
16+
"version": "2.26.2",
1017
"repository": {
1118
"type": "git",
1219
"url": "git://github.com/SAP/node-hdb.git"
@@ -29,20 +36,23 @@
2936
"node": ">= 18"
3037
},
3138
"dependencies": {
32-
"iconv-lite": "^0.4.18"
39+
"iconv-lite": "0.7.0"
3340
},
3441
"devDependencies": {
35-
"async": "^2.4.1",
36-
"chrome-net": "^3.3.0",
37-
"concat-stream": "^1.5.1",
38-
"coveralls": "^2.13.1",
39-
"fstream": "^1.0.11",
40-
"generic-pool": "^2.4.2",
41-
"istanbul": "^0.4.4",
42-
"mocha": "^3.4.2",
43-
"should": "^10.0.0"
42+
"async": "2.6.4",
43+
"chrome-net": "3.3.4",
44+
"concat-stream": "1.6.2",
45+
"coveralls": "2.13.3",
46+
"fstream": "1.0.12",
47+
"generic-pool": "2.5.4",
48+
"istanbul": "0.4.5",
49+
"mocha": "3.5.3",
50+
"should": "10.0.0"
4451
},
4552
"optionalDependencies": {
46-
"lz4-wasm-nodejs": "^0.9.2"
53+
"lz4-wasm-nodejs": "0.9.2"
54+
},
55+
"overrides": {
56+
"safer-buffer": "2.1.2"
4757
}
4858
}

test/lib.ResultSet.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,5 +549,30 @@ describe('Lib', function () {
549549
});
550550
});
551551

552+
it('should not fail when closed multiple times', function (done) {
553+
let rs = createSimpleResultSet();
554+
rs.closed.should.be.false;
555+
let closeCount = 0;
556+
rs.close(function (err) {
557+
closeCount += 1;
558+
rs.closed.should.be.true;
559+
(err === undefined).should.be.true;
560+
rs.close(function (err) {
561+
closeCount += 1;
562+
(err === undefined).should.be.true;
563+
if (closeCount === 3) {
564+
done();
565+
}
566+
});
567+
});
568+
rs.close(function (err) {
569+
closeCount += 1;
570+
(err === undefined).should.be.true;
571+
if (closeCount === 3) {
572+
done();
573+
}
574+
});
575+
});
576+
552577
});
553578
});

0 commit comments

Comments
 (0)