Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(telegram): 64-bit alignment of client struct #881

Merged
merged 1 commit into from Sep 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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