Skip to content

Commit f025a60

Browse files
Thiago Baukenclaude
andcommitted
review: capture kill channel once before the keep-alive loop
Reading getKillChannel(userID) on every loop iteration re-locked killchannelMu once per second per session (contention under load) and could switch to a replaced channel after a reconnect. Capture the channel once before the loop so each session goroutine listens on its own channel without re-locking. Addresses Gemini Code Assist review on #318. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c190e1e commit f025a60

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

wmiau.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,10 +653,11 @@ func (s *server) startClient(userID string, textjid string, token string, subscr
653653
}
654654

655655
// Keep connected client live until disconnected/killed. Read the kill
656-
// channel through the mutex-guarded helper each iteration so this read
657-
// never races with concurrent map writes/deletes from request goroutines.
656+
// channel once through the mutex-guarded helper; the goroutine then listens
657+
// on its own channel for the rest of its life, so it neither re-locks the
658+
// mutex every second nor risks switching to a replaced channel.
659+
kill, _ := getKillChannel(userID)
658660
for {
659-
kill, _ := getKillChannel(userID)
660661
select {
661662
case <-kill:
662663
log.Info().Str("userid", userID).Msg("Received kill signal")

0 commit comments

Comments
 (0)