Skip to content

Commit 0badd1f

Browse files
committed
Introduce sessionConnectionTimeout and updateRoutingTableTimeout (#966)
`sessionConnnectionTimeout` is the maximum amount of time the session will wait when trying to establish a usable read/write connection to the remote host. This encompasses *everything* that needs to happen for this, including, if necessary, updating the routing table<sup>1</sup>, fetching a connection from the pool, and, if necessary performing a BOLT and Authentication handshake with the reader/writer. `updateRoutingTableTimeout` is the maximum amount of time the driver will attempt to fetch a new routing table. This encompasses *everything* that needs to happen for this, including fetching connections from the pool, performing handshakes, and requesting and receiving a fresh routing table. <sup>1</sup>Updating the routing table in turn might also require fetching a connection for the pool and performing the handshakes, plus potentially trying other routers.
1 parent ac6c406 commit 0badd1f

File tree

14 files changed

+963
-150
lines changed

14 files changed

+963
-150
lines changed

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
ConnectionErrorHandler
2525
} from '../connection'
2626
import { internal, error } from 'neo4j-driver-core'
27+
import { controller } from '../lang'
2728

2829
const {
2930
constants: { BOLT_PROTOCOL_V3, BOLT_PROTOCOL_V4_0, BOLT_PROTOCOL_V4_4 }
@@ -49,12 +50,17 @@ export default class DirectConnectionProvider extends PooledConnectionProvider {
4950
this._handleAuthorizationExpired(error, address, database)
5051
})
5152

52-
return this._connectionPool
53-
.acquire(this._address)
54-
.then(
55-
connection =>
56-
new DelegateConnection(connection, databaseSpecificErrorHandler)
57-
)
53+
const acquireConnectionJob = {
54+
run: () => this._connectionPool
55+
.acquire(this._address)
56+
.then(
57+
connection =>
58+
new DelegateConnection(connection, databaseSpecificErrorHandler)
59+
),
60+
onTimeout: connection => connection._release()
61+
}
62+
63+
return controller.runWithTimeout(this._sessionConnectionTimeoutConfig, acquireConnectionJob)
5864
}
5965

6066
_handleAuthorizationExpired (error, address, database) {

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import { createChannelConnection, ConnectionErrorHandler } from '../connection'
2121
import Pool, { PoolConfig } from '../pool'
22-
import { error, ConnectionProvider } from 'neo4j-driver-core'
22+
import { error, newError, ConnectionProvider } from 'neo4j-driver-core'
2323

2424
const { SERVICE_UNAVAILABLE } = error
2525
export default class PooledConnectionProvider extends ConnectionProvider {
@@ -58,6 +58,12 @@ export default class PooledConnectionProvider extends ConnectionProvider {
5858
log: this._log
5959
})
6060
this._openConnections = {}
61+
this._sessionConnectionTimeoutConfig = {
62+
timeout: this._config.sessionConnectionTimeout,
63+
reason: () => newError(
64+
`Session acquisition timed out in ${this._config.sessionConnectionTimeout} ms.`
65+
)
66+
}
6167
}
6268

6369
_createConnectionErrorHandler () {

0 commit comments

Comments
 (0)