Skip to content

Commit a7acf57

Browse files
committed
Fixed purging of connections after rediscovery
After rediscovery newly obtained routing table is compared to the known routing table to find all servers that are "stale" - in the current table but not in the new one. Connections to such servers are supposed to be terminated. However this did not happen because purging function was not invoked correctly. This commit fixes the issue.
1 parent 51c7d8f commit a7acf57

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/v1/routing-driver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class RoutingDriver extends Driver {
145145

146146
// close old connections to servers not present in the new routing table
147147
const staleServers = currentRoutingTable.serversDiff(newRoutingTable);
148-
staleServers.forEach(server => this._pool.purge);
148+
staleServers.forEach(server => this._pool.purge(server));
149149

150150
// make this driver instance aware of the new table
151151
this._routingTable = newRoutingTable;

test/v1/routing.driver.boltkit.it.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,37 @@ describe('routing driver', () => {
6464
});
6565
});
6666

67+
it('should purge connections to stale servers after routing table refresh', done => {
68+
if (!boltkit.BoltKitSupport) {
69+
done();
70+
return;
71+
}
72+
73+
const kit = new boltkit.BoltKit();
74+
const router = kit.start('./test/resources/boltkit/acquire_endpoints.script', 9042);
75+
const reader = kit.start('./test/resources/boltkit/read_server.script', 9005);
76+
77+
kit.run(() => {
78+
const driver = newDriver('bolt+routing://127.0.0.1:9042');
79+
const session = driver.session(neo4j.session.READ);
80+
session.run('MATCH (n) RETURN n.name').then(() => {
81+
session.close();
82+
83+
expect(driver._pool.has('127.0.0.1:9042')).toBeFalsy();
84+
expect(driver._pool.has('127.0.0.1:9005')).toBeTruthy();
85+
86+
driver.close();
87+
router.exit(routerCode => {
88+
reader.exit(readerCode => {
89+
expect(routerCode).toEqual(0);
90+
expect(readerCode).toEqual(0);
91+
done();
92+
});
93+
});
94+
});
95+
});
96+
});
97+
6798
it('should discover new servers', done => {
6899
if (!boltkit.BoltKitSupport) {
69100
done();

0 commit comments

Comments
 (0)