From e7f0728845f4d2772e4640613ce834cabe428cce Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Thu, 12 Nov 2026 11:46:38 +0200 Subject: [PATCH] client: serialize unified-session interval checks --- CHANGELOG.md | 1 + client.go | 4 ++++ client_unified_session_test.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 client_unified_session_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index d4255d181..989e51f9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ All notable HyperMeow changes are documented here. HyperMeow uses commit pseudo- - Preserve reported newsletter counter presence, explicit zeros and distinct view definitions. Omit malformed or ambiguous observations, including duplicate view definitions, instead of reporting fabricated zeros or truncated reaction lists. - Copy group-cache metadata under its lock before send-permission checks, including participant and admin slices, so notifications cannot race those reads. - Stop automatic reconnect and emit `CATRefreshError` to generic and connection-scoped observers when a 413/414 failure cannot refresh its token, including when `RefreshCAT` is unset. The missing callback returns `ErrCATRefreshUnavailable` instead of retrying unchanged credentials. +- Protect the unified-session interval check during concurrent sends. - Keep connection handler completion pending until an active handler exits, and process retired stream errors before automatic reconnect decisions. Manual disconnect retains its five-second wait bound. - Keep the newest pairing secret through bursts of rotation notifications and refresh the active QR code. - Report the destination in `SendFBMessage` responses and decrypt full bot edits using their target message ID. diff --git a/client.go b/client.go index 177db403f..7630e473b 100644 --- a/client.go +++ b/client.go @@ -120,6 +120,7 @@ type Client struct { EnableDecryptedEventBuffer bool synchronousMessageNameUpdates atomic.Bool lastDecryptedBufferClear time.Time + unifiedSessionLock sync.Mutex lastUnifiedSessionSend time.Time UnifiedSessionInterval time.Duration @@ -1345,10 +1346,13 @@ func (cli *Client) sendUnifiedSession(checkLastSend bool) { if cli == nil { return } + cli.unifiedSessionLock.Lock() if checkLastSend && time.Since(cli.lastUnifiedSessionSend) < cli.UnifiedSessionInterval { + cli.unifiedSessionLock.Unlock() return } cli.lastUnifiedSessionSend = time.Now() + cli.unifiedSessionLock.Unlock() node := waBinary.Node{ Tag: "ib", Attrs: waBinary.Attrs{}, diff --git a/client_unified_session_test.go b/client_unified_session_test.go new file mode 100644 index 000000000..08364f18c --- /dev/null +++ b/client_unified_session_test.go @@ -0,0 +1,30 @@ +package whatsmeow + +import ( + "slices" + "sync" + "testing" + "time" +) + +func TestConcurrentUnifiedSessionChecksRespectInterval(t *testing.T) { + cli, _, sent := newTestRemote(t) + cli.UnifiedSessionInterval = time.Hour + start := make(chan struct{}) + var workers sync.WaitGroup + for range 32 { + workers.Go(func() { + <-start + cli.sendUnifiedSession(true) + }) + } + close(start) + workers.Wait() + if tags := sent.tags(); !slices.Equal(tags, []string{"ib:"}) { + t.Fatalf("concurrent interval checks sent %v", tags) + } + cli.sendUnifiedSession(false) + if len(sent.tags()) != 2 { + t.Fatal("explicit unified-session send was incorrectly suppressed") + } +}