fix(tgbot): read the admin list and running flag under their mutex (#6491)

Start and Stop replace adminIds under tgBotMutex, but the report cron, the
backup job and every incoming callback (checkAdmin) read it unlocked. A
concurrent read of a slice header being replaced is not a benign race: it can
observe a torn header and iterate past the backing array. The readers now take
a snapshot under the same lock, and SendMsgToTgbot uses the existing IsRunning
accessor instead of reading the flag directly.
This commit is contained in:
BlindMaster24
2026-09-13 12:46:36 +03:00
committed by GitHub
parent 7ac5277c4f
commit 615876b2eb
5 changed files with 90 additions and 7 deletions
+8
View File
@@ -440,6 +440,14 @@ func (t *Tgbot) IsRunning() bool {
return isRunning
}
// adminSnapshot returns the admin chat list under the mutex Start and Stop
// replace it under: a torn slice header is not a harmless race.
func adminSnapshot() []int64 {
tgBotMutex.Lock()
defer tgBotMutex.Unlock()
return slices.Clone(adminIds)
}
// SetHostname sets the hostname for the bot.
func (t *Tgbot) SetHostname() {
host, err := os.Hostname()