fix: add goroutine safety to Discord typing indicator
- Add 5-minute timeout as safety net to prevent indefinite goroutine leaks when agent produces no outbound message (empty response, panic, etc.) - Listen on c.ctx.Done() so goroutine exits when channel context is cancelled - Log ChannelTyping() errors at debug level for diagnostics (rate limits, session closed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e71822f502
commit
2f8aa1b8d9
1 changed files with 11 additions and 2 deletions
|
|
@ -295,15 +295,24 @@ func (c *DiscordChannel) startTyping(chatID string) {
|
||||||
c.typingMu.Unlock()
|
c.typingMu.Unlock()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
c.session.ChannelTyping(chatID)
|
if err := c.session.ChannelTyping(chatID); err != nil {
|
||||||
|
logger.DebugCF("discord", "ChannelTyping error", map[string]interface{}{"chatID": chatID, "err": err})
|
||||||
|
}
|
||||||
ticker := time.NewTicker(8 * time.Second)
|
ticker := time.NewTicker(8 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
timeout := time.After(5 * time.Minute)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-stop:
|
case <-stop:
|
||||||
return
|
return
|
||||||
|
case <-timeout:
|
||||||
|
return
|
||||||
|
case <-c.ctx.Done():
|
||||||
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
c.session.ChannelTyping(chatID)
|
if err := c.session.ChannelTyping(chatID); err != nil {
|
||||||
|
logger.DebugCF("discord", "ChannelTyping error", map[string]interface{}{"chatID": chatID, "err": err})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue