Skip to content

Commit

Permalink
🎨 seqno mutex moved to better position
Browse files Browse the repository at this point in the history
  • Loading branch information
quenbyako committed Mar 24, 2021
1 parent f28d9fc commit 74aa046
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ func (m *MTProto) sendPacket(request tl.Object, expectedTypes ...reflect.Type) (
m.responseChannels.Add(int(msgID), resp)
}

// must write synchroniously, cuz seqno must be upper each request
m.seqNoMutex.Lock()
defer m.seqNoMutex.Unlock()

if m.encrypted {
data = &messages.Encrypted{
Msg: msg,
Expand All @@ -71,6 +67,10 @@ func (m *MTProto) sendPacket(request tl.Object, expectedTypes ...reflect.Type) (
}
}

// must write synchroniously, cuz seqno must be upper each request
m.seqNoMutex.Lock()
defer m.seqNoMutex.Unlock()

err = m.transport.WriteMsg(data, requireToAck)
if err != nil {
return nil, errors.Wrap(err, "sending request")
Expand Down

0 comments on commit 74aa046

Please sign in to comment.