fix(core): getState requests not scheduling properly

This commit is contained in:
alina 🌸 2023-12-11 01:03:19 +03:00
parent d1e4a15f81
commit ce2d1b0a9a
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI

View file

@ -41,6 +41,7 @@ export interface SessionConnectionParams extends PersistentConnectionParams {
const TEMP_AUTH_KEY_EXPIRY = 86400 // 24 hours const TEMP_AUTH_KEY_EXPIRY = 86400 // 24 hours
const PING_INTERVAL = 60000 // 1 minute const PING_INTERVAL = 60000 // 1 minute
const GET_STATE_INTERVAL = 1500 // 1.5 seconds
// destroy_auth_key#d1435160 = DestroyAuthKeyRes; // destroy_auth_key#d1435160 = DestroyAuthKeyRes;
// const DESTROY_AUTH_KEY = Buffer.from('605134d1', 'hex') // const DESTROY_AUTH_KEY = Buffer.from('605134d1', 'hex')
@ -1163,7 +1164,7 @@ export class SessionConnection extends PersistentConnection {
case 2: case 2:
case 3: case 3:
// message wasn't received by the server // message wasn't received by the server
this._onMessageFailed(msgId, `message info state ${status}`) return this._onMessageFailed(msgId, `message info state ${status}`)
break break
case 0: case 0:
@ -1192,6 +1193,12 @@ export class SessionConnection extends PersistentConnection {
return return
} }
if (answerMsgId.isZero()) {
this.log.debug('received message info for %l: message is still pending (status = %d)', msgId, status)
return
}
this.log.debug('received message info for %l, and answer (%l) was already received', msgId, answerMsgId) this.log.debug('received message info for %l, and answer (%l) was already received', msgId, answerMsgId)
} }
@ -1474,7 +1481,10 @@ export class SessionConnection extends PersistentConnection {
// between multiple connections using the same session // between multiple connections using the same session
this._flushTimer.emitWhenIdle() this._flushTimer.emitWhenIdle()
} else { } else {
this._flushTimer.emitBefore(this._session.lastPingTime + PING_INTERVAL) const nextPingTime = this._session.lastPingTime + PING_INTERVAL
const nextGetScheduleTime = this._session.getStateSchedule.raw[0]?.getState || Infinity
this._flushTimer.emitBefore(Math.min(nextPingTime, nextGetScheduleTime))
} }
} }
@ -1533,7 +1543,7 @@ export class SessionConnection extends PersistentConnection {
messageCount += 1 messageCount += 1
} }
const getStateTime = now + 1500 const getStateTime = now + GET_STATE_INTERVAL
if (now - this._session.lastPingTime > PING_INTERVAL) { if (now - this._session.lastPingTime > PING_INTERVAL) {
if (!this._session.lastPingMsgId.isZero()) { if (!this._session.lastPingMsgId.isZero()) {