Skip to content

Handle AuthorisationExpired during rediscovery #803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,14 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
async _createSessionForRediscovery (routerAddress, bookmark, impersonatedUser) {
try {
const connection = await this._connectionPool.acquire(routerAddress)
const connectionProvider = new SingleConnectionProvider(connection)

const databaseSpecificErrorHandler = ConnectionErrorHandler.create({
errorCode: SESSION_EXPIRED,
handleAuthorizationExpired: (error, address) => this._handleAuthorizationExpired(error, address)
})

const connectionProvider = new SingleConnectionProvider(
new DelegateConnection(connection, databaseSpecificErrorHandler))

const protocolVersion = connection.protocol().version
if (protocolVersion < 4.0) {
Expand Down
12 changes: 10 additions & 2 deletions packages/neo4j-driver/test/internal/shared-neo4j.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,25 @@ function restart (configOverride) {
startNeo4j()
}

async function cleanupAndGetProtocolVersion (driver) {
async function cleanupAndGetProtocolVersionAndBookmark (driver) {
const session = driver.session({ defaultAccessMode: neo4j.session.WRITE })
try {
const result = await session.writeTransaction(tx =>
tx.run('MATCH (n) DETACH DELETE n')
)
return result.summary.server.protocolVersion
return [result.summary.server.protocolVersion, session.lastBookmark()]
} finally {
await session.close()
}
}

async function cleanupAndGetProtocolVersion (driver) {
const [protocolVersion] = await cleanupAndGetProtocolVersionAndBookmark(
driver
)
return protocolVersion
}

async function getEdition (driver) {
const session = driver.session({ defaultAccessMode: neo4j.session.READ })
try {
Expand Down Expand Up @@ -375,6 +382,7 @@ export default {
authToken: authToken,
logging: debugLogging,
cleanupAndGetProtocolVersion: cleanupAndGetProtocolVersion,
cleanupAndGetProtocolVersionAndBookmark,
tlsConfig: tlsConfig,
getEdition: getEdition,
hostname: hostname,
Expand Down
20 changes: 14 additions & 6 deletions packages/neo4j-driver/test/stress-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export default async function execute () {
neo4j.auth.basic(USERNAME, PASSWORD),
config
)
const protocolVersion = await sharedNeo4j.cleanupAndGetProtocolVersion(driver)
const [
protocolVersion,
bookmarks
] = await sharedNeo4j.cleanupAndGetProtocolVersionAndBookmark(driver)
console.time('Basic-stress-test')
const printStats = () => {
console.timeEnd('Basic-stress-test')
Expand All @@ -83,7 +86,12 @@ export default async function execute () {
console.log('Write statistics: ', context.writeServersWithQueryCount)
}

const context = new Context(driver, LOGGING_ENABLED, protocolVersion)
const context = new Context(
driver,
LOGGING_ENABLED,
protocolVersion,
bookmarks
)

try {
await runWhileNotTimeout(async () => {
Expand Down Expand Up @@ -525,10 +533,10 @@ function noParams () {
}

function newSession (context, accessMode, useBookmark) {
if (useBookmark) {
if (useBookmark || isCluster()) {
return context.driver.session({
defaultAccessMode: accessMode,
bookmarks: [context.bookmark]
bookmarks: context.bookmark
})
}
return context.driver.session({ defaultAccessMode: accessMode })
Expand Down Expand Up @@ -556,9 +564,9 @@ function arraysEqual (array1, array2) {
}

class Context {
constructor (driver, loggingEnabled, protocolVersion) {
constructor (driver, loggingEnabled, protocolVersion, bookmark) {
this.driver = driver
this.bookmark = null
this.bookmark = bookmark
this.createdNodesCount = 0
this._commandIdCouter = 0
this._loggingEnabled = loggingEnabled
Expand Down