Try to fix WS race condition connection (#4976)

* Try to fix wrong token logic

* Linting
This commit is contained in:
Nicolas Gotchac 2017-03-21 17:01:33 +01:00 committed by Jaco Greeff
parent cb881108c3
commit c7e6992239

View File

@ -241,7 +241,7 @@ export default class SecureApi extends Api {
this.transport.updateToken(token, false);
log.debug('connecting with token', token);
return this.transport.connect()
const connectPromise = this.transport.connect()
.then(() => {
log.debug('connected with', token);
@ -258,9 +258,19 @@ export default class SecureApi extends Api {
log.debug('did not connect ; error', error);
}
// Check if the Node is up
return this.isNodeUp()
.then((isNodeUp) => {
return false;
});
return Promise
.all([
connectPromise,
this.isNodeUp()
])
.then(([ connected, isNodeUp ]) => {
if (connected) {
return true;
}
// If it's not up, try again in a few...
if (!isNodeUp) {
const timeout = this.transport.retryTimeout;
@ -278,7 +288,6 @@ export default class SecureApi extends Api {
log.debug('tried with a wrong token', token);
return false;
});
});
}
/**