From 0dd6d70c60f27f70cbec83d0207400f3bb8d9cd3 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Wed, 14 Oct 2020 20:42:27 +0200 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. (Backported from https://github.com/sochix/TLSharp/commit/1b06473108fb41e1b1fc5913b63782edf240a495) --- src/TgSharp.Core/Network/MtProtoSender.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/TgSharp.Core/Network/MtProtoSender.cs b/src/TgSharp.Core/Network/MtProtoSender.cs index 04295a2..932bde6 100644 --- a/src/TgSharp.Core/Network/MtProtoSender.cs +++ b/src/TgSharp.Core/Network/MtProtoSender.cs @@ -38,7 +38,11 @@ namespace TgSharp.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 { + sessionStore.Save(session); + } } }