fix(core): hopefully fix duplicating msg_id leading to bad_msg_container 64
This commit is contained in:
parent
e20bc02a0b
commit
9091a10537
2 changed files with 8 additions and 3 deletions
|
@ -170,6 +170,7 @@ export class MtprotoSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTimeOffset(offset: number) {
|
updateTimeOffset(offset: number) {
|
||||||
|
this.log.debug('time offset updated: %d', offset)
|
||||||
this._timeOffset = offset
|
this._timeOffset = offset
|
||||||
// lastMessageId was generated with (potentially) wrong time
|
// lastMessageId was generated with (potentially) wrong time
|
||||||
// reset it to avoid bigger issues - at worst, we'll get bad_msg_notification
|
// reset it to avoid bigger issues - at worst, we'll get bad_msg_notification
|
||||||
|
@ -243,7 +244,7 @@ export class MtprotoSession {
|
||||||
|
|
||||||
let messageId = new Long((timeMSec << 21) | (random << 3) | 4, timeSec)
|
let messageId = new Long((timeMSec << 21) | (random << 3) | 4, timeSec)
|
||||||
|
|
||||||
if (this._lastMessageId.gt(messageId)) {
|
if (this._lastMessageId.ge(messageId)) {
|
||||||
messageId = this._lastMessageId.add(4)
|
messageId = this._lastMessageId.add(4)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -954,9 +954,10 @@ export class SessionConnection extends PersistentConnection {
|
||||||
private _onAllFailed(reason: string) {
|
private _onAllFailed(reason: string) {
|
||||||
// called when all the pending messages are to be resent
|
// called when all the pending messages are to be resent
|
||||||
// e.g. when server returns 429
|
// e.g. when server returns 429
|
||||||
|
|
||||||
// most service messages can be omitted as stale
|
// most service messages can be omitted as stale
|
||||||
|
|
||||||
|
this.log.debug('all messages failed because of %s', reason)
|
||||||
|
|
||||||
for (const msgId of this._session.pendingMessages.keys()) {
|
for (const msgId of this._session.pendingMessages.keys()) {
|
||||||
const info = this._session.pendingMessages.get(msgId)!
|
const info = this._session.pendingMessages.get(msgId)!
|
||||||
|
|
||||||
|
@ -966,6 +967,7 @@ export class SessionConnection extends PersistentConnection {
|
||||||
case 'resend':
|
case 'resend':
|
||||||
case 'ping':
|
case 'ping':
|
||||||
// no longer relevant
|
// no longer relevant
|
||||||
|
this.log.debug('forgetting about %s message %l', info._, msgId)
|
||||||
this._session.pendingMessages.delete(msgId)
|
this._session.pendingMessages.delete(msgId)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
@ -1949,10 +1951,12 @@ export class SessionConnection extends PersistentConnection {
|
||||||
packetSize = writer.pos
|
packetSize = writer.pos
|
||||||
|
|
||||||
const containerId = this._session.getMessageId()
|
const containerId = this._session.getMessageId()
|
||||||
|
const seqNo = this._session.getSeqNo(false)
|
||||||
|
this.log.debug('container: msg_id assigned %l, seqno: %d', containerId, seqNo)
|
||||||
writer.pos = 0
|
writer.pos = 0
|
||||||
rootMsgId = containerId
|
rootMsgId = containerId
|
||||||
writer.long(this._registerOutgoingMsgId(containerId))
|
writer.long(this._registerOutgoingMsgId(containerId))
|
||||||
writer.uint(this._session.getSeqNo(false))
|
writer.uint(seqNo)
|
||||||
writer.uint(packetSize - 16)
|
writer.uint(packetSize - 16)
|
||||||
writer.pos = packetSize
|
writer.pos = packetSize
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue