Skip to content

Commit b7e2198

Browse files
authored
Improve purge address of the Pool routine (#995)
In Browser environments, the WebSocket release can take seconds to finish. This behaviour can make LDAP authentication expired take more time than usual. Purging the connection in parallel speeds up this process.
1 parent f2312da commit b7e2198

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

packages/bolt-connection/src/pool/pool.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,18 @@ class Pool {
292292

293293
async _purgeKey (key) {
294294
const pool = this._pools[key]
295+
const destructionList = []
295296
if (pool) {
296297
while (pool.length) {
297298
const resource = pool.pop()
298299
if (this._removeIdleObserver) {
299300
this._removeIdleObserver(resource)
300301
}
301-
await this._destroy(resource)
302+
destructionList.push(this._destroy(resource))
302303
}
303304
pool.close()
304305
delete this._pools[key]
306+
await Promise.all(destructionList)
305307
}
306308
}
307309

packages/bolt-connection/test/pool/pool.test.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ describe('#unit Pool', () => {
878878
expect(resource2.observer).toBeFalsy()
879879
})
880880

881-
it('should thrown aquisition timeout exception if resource takes longer to be created', async () => {
881+
it('should thrown acquisition timeout exception if resource takes longer to be created', async () => {
882882
const address = ServerAddress.fromUrl('bolt://localhost:7687')
883883
const acquisitionTimeout = 1000
884884
let counter = 0
@@ -911,6 +911,43 @@ describe('#unit Pool', () => {
911911
expect(counter).toEqual(1)
912912
}
913913
})
914+
915+
it('should purge resources in parallel', async () => {
916+
const address = ServerAddress.fromUrl('bolt://localhost:7687')
917+
let resourceCount = 0
918+
const resourcesReleased = []
919+
let resolveRelease
920+
const releasePromise = new Promise((resolve) => {
921+
resolveRelease = resolve
922+
})
923+
924+
const pool = new Pool({
925+
create: (server, release) =>
926+
Promise.resolve(new Resource(server, resourceCount++, release)),
927+
destroy: res => {
928+
resourcesReleased.push(res)
929+
resourceCount--
930+
// Only destroy when the last resource
931+
// get destroyed
932+
if (resourceCount === 0) {
933+
resolveRelease()
934+
}
935+
return releasePromise
936+
},
937+
validate: res => true
938+
})
939+
940+
const resource1 = await pool.acquire(address)
941+
const resource2 = await pool.acquire(address)
942+
await resource1.close()
943+
await resource2.close()
944+
945+
await pool.purge(address)
946+
947+
expect(resourcesReleased).toEqual([
948+
resource2, resource1
949+
])
950+
})
914951
})
915952

916953
function expectNoPendingAcquisitionRequests (pool) {

packages/neo4j-driver/test/temporal-types.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ describe('#integration temporal-types', () => {
354354
await testSendAndReceiveRandomTemporalValues(() => randomLocalDateTime())
355355
}, 60000)
356356

357-
it('should send and receive random LocalDateTime', async () => {
357+
it('should send and receive array of random LocalDateTime', async () => {
358358
if (neo4jDoesNotSupportTemporalTypes()) {
359359
return
360360
}

0 commit comments

Comments
 (0)