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