mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix: address PR #662 review comments (bus drain, context timeouts, onebot leak)
- Drain buffered messages in MessageBus.Close() so they aren't silently lost - Replace all context.TODO() with context.WithTimeout(5s) across 7 call sites - Fix OneBot pending channel leak: send nil sentinel in Stop() and handle nil response in sendAPIRequest() to unblock waiting goroutines
This commit is contained in:
@@ -306,6 +306,9 @@ func (c *OneBotChannel) sendAPIRequest(action string, params any, timeout time.D
|
||||
|
||||
select {
|
||||
case resp := <-ch:
|
||||
if resp == nil {
|
||||
return nil, fmt.Errorf("API request %s: channel stopped", action)
|
||||
}
|
||||
return resp, nil
|
||||
case <-time.After(timeout):
|
||||
return nil, fmt.Errorf("API request %s timed out after %v", action, timeout)
|
||||
@@ -353,7 +356,11 @@ func (c *OneBotChannel) Stop(ctx context.Context) error {
|
||||
}
|
||||
|
||||
c.pendingMu.Lock()
|
||||
for echo := range c.pending {
|
||||
for echo, ch := range c.pending {
|
||||
select {
|
||||
case ch <- nil: // non-blocking wake for blocked sendAPIRequest goroutines
|
||||
default:
|
||||
}
|
||||
delete(c.pending, echo)
|
||||
}
|
||||
c.pendingMu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user