Skip to content

Commit a49ea01

Browse files
authored
Unify Connection Acquisition Timeout with other Drivers (#1292)
we’ve decided upon unifying the drivers to consider the timeout to count towards everything needed for acquiring a connection. This can include multiple connection acquisitions, ROUTE request, custom resolver/provider calls, etc; anything that’s needed to get a connection for the session.
1 parent 5d8916b commit a49ea01

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

packages/bolt-connection/src/connection-provider/connection-provider-routing.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
8989
this._loadBalancingStrategy = new LeastConnectedLoadBalancingStrategy(
9090
this._connectionPool
9191
)
92+
this._startTime = 0
9293
this._hostNameResolver = hostNameResolver
9394
this._dnsResolver = new HostNameResolver()
9495
this._log = log
@@ -152,6 +153,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
152153
(error, address, conn) => this._handleSecurityError(error, address, conn, context.database)
153154
)
154155

156+
this._startTime = new Date().getTime()
155157
let conn
156158
if (this.SSREnabled() && homeDb !== undefined && database === '') {
157159
const currentRoutingTable = this._routingTableRegistry.get(
@@ -205,7 +207,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
205207
}
206208

207209
try {
208-
const connection = await this._connectionPool.acquire({ auth }, address)
210+
const connection = await this._connectionPool.acquire({ auth, startTime: this._startTime }, address)
209211

210212
if (auth) {
211213
await this._verifyStickyConnection({
@@ -585,7 +587,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
585587

586588
async _createSessionForRediscovery (routerAddress, bookmarks, impersonatedUser, auth) {
587589
try {
588-
const connection = await this._connectionPool.acquire({ auth }, routerAddress)
590+
const connection = await this._connectionPool.acquire({ auth, startTime: this._startTime }, routerAddress)
589591

590592
if (auth) {
591593
await this._verifyStickyConnection({

packages/bolt-connection/test/connection-provider/connection-provider-routing.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,7 +3494,7 @@ describe.each([
34943494
.catch(functional.identity)
34953495

34963496
expect(error).toEqual(newError('Driver is connected to a database that does not support user switch.'))
3497-
expect(poolAcquire).toHaveBeenCalledWith({ auth }, server3)
3497+
expect(poolAcquire).toHaveBeenCalledWith({ auth, startTime: expect.any(Number) }, server3)
34983498
expect(connection.release).toHaveBeenCalled()
34993499
expect(connection._sticky).toEqual(isStickyConn)
35003500
})
@@ -3536,7 +3536,7 @@ describe.each([
35363536
.catch(functional.identity)
35373537

35383538
expect(error).toEqual(newError('Driver is connected to a database that does not support user switch.'))
3539-
expect(poolAcquire).toHaveBeenCalledWith({ auth }, server1)
3539+
expect(poolAcquire).toHaveBeenCalledWith({ auth, startTime: expect.any(Number) }, server1)
35403540
expect(connection.release).toHaveBeenCalled()
35413541
expect(connection._sticky).toEqual(isStickyConn)
35423542
})
@@ -3580,7 +3580,7 @@ describe.each([
35803580
.catch(functional.identity)
35813581

35823582
expect(error).toEqual(newError('Driver is connected to a database that does not support user switch.'))
3583-
expect(poolAcquire).toHaveBeenCalledWith({ auth }, server0)
3583+
expect(poolAcquire).toHaveBeenCalledWith({ auth, startTime: expect.any(Number) }, server0)
35843584
expect(connection.release).toHaveBeenCalled()
35853585
expect(connection._sticky).toEqual(isStickyConn)
35863586
})
@@ -3609,7 +3609,7 @@ describe.each([
36093609
.catch(functional.identity)
36103610

36113611
expect(error).toEqual(newError('Driver is connected to a database that does not support user switch.'))
3612-
expect(poolAcquire).toHaveBeenCalledWith({ auth }, server0)
3612+
expect(poolAcquire).toHaveBeenCalledWith({ auth, startTime: expect.any(Number) }, server0)
36133613
expect(connection.release).toHaveBeenCalled()
36143614
expect(connection._sticky).toEqual(isStickyConn)
36153615
})

packages/core/src/internal/pool/pool.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type ValidateOnRelease<R extends unknown = unknown> = (resource: R) => (Promise<
2828
type InstallObserver<R extends unknown = unknown> = (resource: R, observer: unknown) => void
2929
type RemoveObserver<R extends unknown = unknown> = (resource: R) => void
3030
interface AcquisitionConfig { requireNew?: boolean }
31+
interface AcquisitionContext { startTime?: number, forceReAuth?: boolean, skipReAuth?: boolean, auth?: object, triggerValidation?: boolean }
3132

3233
interface ConstructorParam<R extends unknown = unknown> {
3334
create?: Create<R>
@@ -111,12 +112,13 @@ class Pool<R extends unknown = unknown> {
111112
* @param {boolean} config.requireNew Indicate it requires a new resource
112113
* @return {Promise<Object>} resource that is ready to use.
113114
*/
114-
async acquire (acquisitionContext: unknown, address: ServerAddress, config?: AcquisitionConfig): Promise<R> {
115+
async acquire (acquisitionContext: AcquisitionContext, address: ServerAddress, config?: AcquisitionConfig): Promise<R> {
115116
const key = address.asKey()
116117

117118
// We're out of resources and will try to acquire later on when an existing resource is released.
118119
const allRequests = this._acquireRequests
119120
const requests = allRequests[key]
121+
const elapsedTime = (acquisitionContext.startTime != null && acquisitionContext.startTime !== 0) ? new Date().getTime() - acquisitionContext.startTime : 0
120122
if (requests == null) {
121123
allRequests[key] = []
122124
}
@@ -143,7 +145,7 @@ class Pool<R extends unknown = unknown> {
143145
)
144146
)
145147
}
146-
}, this._acquisitionTimeout)
148+
}, this._acquisitionTimeout - elapsedTime)
147149

148150
if (typeof timeoutId === 'object') {
149151
// eslint-disable-next-line

packages/neo4j-driver-deno/lib/bolt-connection/connection-provider/connection-provider-routing.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/neo4j-driver-deno/lib/core/internal/pool/pool.ts

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/testkit-backend/src/skipped-tests/common.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ const skippedTests = [
198198
skip(
199199
'Needs trying all DNS resolved addresses for hosts in the routing table',
200200
ifEndsWith('.test_ipv6_read').and(startsWith('stub.routing.test_routing_'))
201-
),
202-
skip(
203-
'Driver has separate timeouts for every connection it attempts to open. This will change in 6.0',
204-
ifEquals('stub.homedb.test_homedb.TestHomeDbMixedCluster.test_connection_acquisition_timeout_during_fallback')
205201
)
206202
]
207203

0 commit comments

Comments
 (0)