From 8cff6cf3123c71bacf0ee534352a3cac55e2b3f0 Mon Sep 17 00:00:00 2001 From: Hoshina Date: Sat, 14 Feb 2026 20:25:55 +0800 Subject: [PATCH] fix: improve connection handling in OneBotChannel --- pkg/channels/onebot.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/channels/onebot.go b/pkg/channels/onebot.go index 674acf5..5d97fab 100644 --- a/pkg/channels/onebot.go +++ b/pkg/channels/onebot.go @@ -116,13 +116,20 @@ func (c *OneBotChannel) Start(ctx context.Context) error { c.ctx, c.cancel = context.WithCancel(ctx) if err := c.connect(); err != nil { - return fmt.Errorf("failed to connect to OneBot: %w", err) + logger.WarnCF("onebot", "Initial connection failed, will retry in background", map[string]interface{}{ + "error": err.Error(), + }) + } else { + go c.listen() } - go c.listen() - if c.config.ReconnectInterval > 0 { go c.reconnectLoop() + } else { + // If reconnect is disabled but initial connection failed, we cannot recover + if c.conn == nil { + return fmt.Errorf("failed to connect to OneBot and reconnect is disabled") + } } c.setRunning(true)