Eliminate busy-loop in dispatchOutbound when context is cancelled

This commit is contained in:
Yasuhiro Matsumoto 2026-02-16 00:59:09 +09:00
parent 214b201bfa
commit d7084052b7
No known key found for this signature in database
GPG key ID: F2EA90DF2C146D1E

View file

@ -246,38 +246,33 @@ func (m *Manager) dispatchOutbound(ctx context.Context) {
logger.InfoC("channels", "Outbound dispatcher started") logger.InfoC("channels", "Outbound dispatcher started")
for { for {
select { msg, ok := m.bus.SubscribeOutbound(ctx)
case <-ctx.Done(): if !ok {
logger.InfoC("channels", "Outbound dispatcher stopped") logger.InfoC("channels", "Outbound dispatcher stopped")
return return
default: }
msg, ok := m.bus.SubscribeOutbound(ctx)
if !ok {
continue
}
// Silently skip internal channels // Silently skip internal channels
if constants.IsInternalChannel(msg.Channel) { if constants.IsInternalChannel(msg.Channel) {
continue continue
} }
m.mu.RLock() m.mu.RLock()
channel, exists := m.channels[msg.Channel] channel, exists := m.channels[msg.Channel]
m.mu.RUnlock() m.mu.RUnlock()
if !exists { if !exists {
logger.WarnCF("channels", "Unknown channel for outbound message", map[string]interface{}{ logger.WarnCF("channels", "Unknown channel for outbound message", map[string]interface{}{
"channel": msg.Channel, "channel": msg.Channel,
}) })
continue continue
} }
if err := channel.Send(ctx, msg); err != nil { if err := channel.Send(ctx, msg); err != nil {
logger.ErrorCF("channels", "Error sending message to channel", map[string]interface{}{ logger.ErrorCF("channels", "Error sending message to channel", map[string]interface{}{
"channel": msg.Channel, "channel": msg.Channel,
"error": err.Error(), "error": err.Error(),
}) })
}
} }
} }
} }