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 1b06473108)
This commit is contained in:
Andres G. Aragoneses 2020-10-14 20:42:27 +02:00
parent 79ad0fc21e
commit 0dd6d70c60

View file

@ -38,7 +38,11 @@ namespace TgSharp.Core.Network
private int GenerateSequence(bool confirmed) private int GenerateSequence(bool confirmed)
{ {
lock (session.Lock) { 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);
}
} }
} }