GramJs: Add reconnect interval, don't sign out on internal server issues (#1341)
This commit is contained in:
parent
8b177b275d
commit
6bcbb78258
@ -398,6 +398,7 @@ class MTProtoSender {
|
|||||||
// this._log.info('Connection closed while receiving data');
|
// this._log.info('Connection closed while receiving data');
|
||||||
/** when the server disconnects us we want to reconnect */
|
/** when the server disconnects us we want to reconnect */
|
||||||
if (!this.userDisconnected) {
|
if (!this.userDisconnected) {
|
||||||
|
this._log.error(e);
|
||||||
this._log.warn('Connection closed while receiving data');
|
this._log.warn('Connection closed while receiving data');
|
||||||
this.reconnect();
|
this.reconnect();
|
||||||
}
|
}
|
||||||
@ -416,23 +417,22 @@ class MTProtoSender {
|
|||||||
this._log.warn(`Security error while unpacking a received message: ${e}`);
|
this._log.warn(`Security error while unpacking a received message: ${e}`);
|
||||||
continue;
|
continue;
|
||||||
} else if (e instanceof InvalidBufferError) {
|
} else if (e instanceof InvalidBufferError) {
|
||||||
this._log.info('Broken authorization key; resetting');
|
// 404 means that the server has "forgotten" our auth key and we need to create a new one.
|
||||||
if (this._updateCallback && this._isMainSender) {
|
if (e.code === 404) {
|
||||||
this._updateCallback(new UpdateConnectionState(UpdateConnectionState.broken));
|
this._log.warn(`Broken authorization key for dc ${this._dcId}; resetting`);
|
||||||
} else if (this._onConnectionBreak && !this._isMainSender) {
|
if (this._updateCallback && this._isMainSender) {
|
||||||
// Deletes the current sender from the object
|
this._updateCallback(new UpdateConnectionState(UpdateConnectionState.broken));
|
||||||
this._onConnectionBreak(this._dcId);
|
} else if (this._onConnectionBreak && !this._isMainSender) {
|
||||||
|
// Deletes the current sender from the object
|
||||||
|
this._onConnectionBreak(this._dcId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// this happens sometimes when telegram is having some internal issues.
|
||||||
|
// reconnecting should be enough usually
|
||||||
|
// since the data we sent and received is probably wrong now.
|
||||||
|
this._log.warn(`Invalid buffer ${e.code} for dc ${this._dcId}`);
|
||||||
|
this.reconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't really need to do this if we're going to sign in again
|
|
||||||
/* await this.authKey.setKey(null)
|
|
||||||
|
|
||||||
if (this._authKeyCallback) {
|
|
||||||
await this._authKeyCallback(null)
|
|
||||||
} */
|
|
||||||
// We can disconnect at sign in
|
|
||||||
/* await this.disconnect()
|
|
||||||
*/
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
this._log.error('Unhandled error while receiving data');
|
this._log.error('Unhandled error while receiving data');
|
||||||
@ -818,8 +818,12 @@ class MTProtoSender {
|
|||||||
this._reconnecting = true;
|
this._reconnecting = true;
|
||||||
// TODO Should we set this?
|
// TODO Should we set this?
|
||||||
// this._user_connected = false
|
// this._user_connected = false
|
||||||
this._log.info('Started reconnecting');
|
// we want to wait a second between each reconnect try to not flood the server with reconnects
|
||||||
this._reconnect();
|
// in case of internal server issues.
|
||||||
|
Helpers.sleep(1000).then(() => {
|
||||||
|
this._log.info('Started reconnecting');
|
||||||
|
this._reconnect();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user