Skip to content

Commit

Permalink
Added reconnection on TokenSecurityException
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Sep 4, 2018
1 parent e2f1ead commit 324169b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/client/database/session.js
Expand Up @@ -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;
Expand All @@ -50,9 +53,11 @@ class SessionManager {
});
}).bind(this)
.then(() => {
this.opening = null;
return this.currentSession;
});
});
return this.opening;
}

current() {
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions lib/errors/request.js
Expand Up @@ -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"
);
};
});

0 comments on commit 324169b

Please sign in to comment.