From 4e932d1e268ed43868ad0bc28b08ff53a9c6c85c Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Thu, 6 Aug 2026 13:17:58 -0400 Subject: [PATCH] Thread-safe access to online flag --- telegram/client.go | 3 ++- telegram/commands.go | 2 +- telegram/connect.go | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/telegram/client.go b/telegram/client.go index 345c6cc..14c8403 100644 --- a/telegram/client.go +++ b/telegram/client.go @@ -5,6 +5,7 @@ import ( "path/filepath" "strconv" "sync" + "sync/atomic" "time" "dev.narayana.im/narayana/telegabber/calls/audio/ntgadapter" @@ -133,7 +134,7 @@ type Client struct { resources map[string]bool content *config.TelegramContentConfig cache *cache.Cache - online bool + online atomic.Bool loginWizard *loginWizardMetadata loginStage LoginStage diff --git a/telegram/commands.go b/telegram/commands.go index f691e7a..765ab91 100644 --- a/telegram/commands.go +++ b/telegram/commands.go @@ -397,7 +397,7 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) (strin c.Session.Login = "" c.wizardStageOrPrompt(LoginStageCancel, "") - c.online = false + c.online.Store(false) // cleanup case "cleanup": c.unsubscribeFromAll() diff --git a/telegram/connect.go b/telegram/connect.go index 99aa854..207fcd6 100644 --- a/telegram/connect.go +++ b/telegram/connect.go @@ -158,7 +158,7 @@ func (c *Client) Connect(resource string, wasSessionLoginEmpty bool) error { go c.updateHandler() log.Warn("Going online") - c.online = true + c.online.Store(true) c.locks.authorizationReady.Unlock() c.addResource(resource) @@ -327,7 +327,7 @@ func (c *Client) forceClose() { defer c.locks.authorizerReadLock.Unlock() defer c.locks.authorizerWriteLock.Unlock() - c.online = false + c.online.Store(false) c.authorizer = nil } @@ -375,5 +375,5 @@ func (c *Client) cancelAuth() { // Online checks if the updates listener is alive func (c *Client) Online() bool { - return c.online + return c.online.Load() }