Skip to content

Commit

Permalink
Merge pull request #881 from iyear/fix-client-64bit-alignment
Browse files Browse the repository at this point in the history
fix(telegram): 64-bit alignment of client struct
  • Loading branch information
ernado committed Sep 17, 2022
2 parents a282f7b + 9f989b8 commit 50ddefd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions telegram/client.go
Expand Up @@ -53,6 +53,15 @@ type clientConn interface {

// Client represents a MTProto client to Telegram.
type Client struct {
// Put migration in the header of the structure to ensure 64-bit alignment,
// otherwise it will cause the atomic operation of connsCounter to panic.
// DO NOT change the order of members arbitrarily.
// Ref: https://pkg.go.dev/sync/atomic#pkg-note-BUG

// Migration state.
migrationTimeout time.Duration // immutable
migration chan struct{}

// tg provides RPC calls via Client. Uses invoker below.
tg *tg.Client // immutable
// invoker implements tg.Invoker on top of Client and mw.
Expand Down Expand Up @@ -86,9 +95,6 @@ type Client struct {

// Restart signal channel.
restart chan struct{} // immutable
// Migration state.
migrationTimeout time.Duration // immutable
migration chan struct{}

// Connections to non-primary DC.
subConns map[int]CloseInvoker
Expand Down

0 comments on commit 50ddefd

Please sign in to comment.