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.
This commit is contained in:
Andres G. Aragoneses 2020-09-21 14:56:11 +08:00
parent 881bdd27a5
commit 1b06473108

View file

@ -35,7 +35,11 @@ namespace TLSharp.Core.Network
private int GenerateSequence(bool confirmed) private int GenerateSequence(bool confirmed)
{ {
lock (session.Lock) { lock (session.Lock) {
try {
return confirmed ? session.Sequence++ * 2 + 1 : session.Sequence * 2; return confirmed ? session.Sequence++ * 2 + 1 : session.Sequence * 2;
} finally {
session.Save ();
}
} }
} }