From 324169b1d86a57c3ae5b06fb66228484638178ab Mon Sep 17 00:00:00 2001 From: wolf4ood Date: Tue, 4 Sep 2018 16:17:02 +0200 Subject: [PATCH] Added reconnection on TokenSecurityException --- lib/client/database/session.js | 9 +++++++-- lib/errors/request.js | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/client/database/session.js b/lib/client/database/session.js index 62a5a02a..ac4db888 100644 --- a/lib/client/database/session.js +++ b/lib/client/database/session.js @@ -24,8 +24,11 @@ class SessionManager { return Promise.resolve(this.currentSession); } + if(this.opening){ + return this.opening; + } this.client.logger.debug('opening database session to ' + this.name); - return this.client.cluster.acquireFrom() + this.opening = this.client.cluster.acquireFrom() .then((resource) => { let server = resource.server; let connection = resource.connection; @@ -50,9 +53,11 @@ class SessionManager { }); }).bind(this) .then(() => { + this.opening = null; return this.currentSession; }); }); + return this.opening; } current() { @@ -164,7 +169,7 @@ class SessionManager { .then(resolve) .catch((err) => { // TODO Handle retry - if (err instanceof ConnectionError) { + if (err instanceof ConnectionError || err.isTokenException()) { this.currentSession = null; this.open().then(this.withSession.bind(this, op, data, acquire, cbk)) .catch(reject); diff --git a/lib/errors/request.js b/lib/errors/request.js index e93981af..31d772a7 100644 --- a/lib/errors/request.js +++ b/lib/errors/request.js @@ -14,4 +14,11 @@ module.exports = OperationError.inherit(function RequestError(message, data) { "com.orientechnologies.orient.core.exception.OConcurrentModificationException" ); }; + + this.isTokenException = () => { + return ( + this.type === + "com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException" + ); + }; });