Skip to content

Commit e9ea0e6

Browse files
committed
Call session _onClose only once
1 parent 89c733e commit e9ea0e6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/v1/session.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,15 @@ class Session {
8787
* @return
8888
*/
8989
close(cb=(()=>null)) {
90-
this._onClose(cb);
90+
if(this._onClose) {
91+
try {
92+
this._onClose(cb);
93+
} finally {
94+
this._onClose = null;
95+
}
96+
} else {
97+
cb();
98+
}
9199
}
92100
}
93101

test/v1/session.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
var neo4j = require("../../lib/v1");
2121
var StatementType = require("../../lib/v1/result-summary").statementType;
22+
var Session = require("../../lib/v1/session");
2223

2324
describe('session', function() {
2425

@@ -35,6 +36,18 @@ describe('session', function() {
3536
driver.close();
3637
});
3738

39+
it('close should be idempotent ', function(){
40+
// Given
41+
var counter = 0;
42+
var _session = new Session(null, function(){
43+
counter++;
44+
});
45+
_session.close();
46+
expect(counter).toBe(1);
47+
_session.close();
48+
expect(counter).toBe(1);
49+
})
50+
3851
it('should expose basic run/subscribe ', function(done) {
3952
// Given
4053

0 commit comments

Comments
 (0)