From 1b06473108fb41e1b1fc5913b63782edf240a495 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Mon, 21 Sep 2020 14:56:11 +0800 Subject: [PATCH] Core: save session as soon as a the sequence is incremented Just be safe, let's not wait until other part of the code saves the session, and let's do it right here on the spot, where we know it changes. @Laituex was having a ErrCode=32 'msg_seqno too low' problem and this is the second thing we suspected to be the culprit, because if there's any issue (e.g. exception) that makes the session not be saved after the sequence got incremented, then an old sequence would be used the next time upon loading an old session file. --- TLSharp.Core/Network/MtProtoSender.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/TLSharp.Core/Network/MtProtoSender.cs b/TLSharp.Core/Network/MtProtoSender.cs index 5cbc9cf..d57b0b5 100644 --- a/TLSharp.Core/Network/MtProtoSender.cs +++ b/TLSharp.Core/Network/MtProtoSender.cs @@ -35,7 +35,11 @@ namespace TLSharp.Core.Network private int GenerateSequence(bool confirmed) { lock (session.Lock) { - return confirmed ? session.Sequence++ * 2 + 1 : session.Sequence * 2; + try { + return confirmed ? session.Sequence++ * 2 + 1 : session.Sequence * 2; + } finally { + session.Save (); + } } }