fix(im/wecom): resolve longconn deadlock between closeConn and heartbeatLoop

main
ycc 2026-08-06 10:16:13 +08:00 committed by lyingbug
parent f16a4ede93
commit 6b0d8d1057
1 changed files with 6 additions and 6 deletions

View File

@ -380,9 +380,7 @@ func (c *LongConnClient) connectAndRun(ctx context.Context) error {
c.mu.Unlock()
defer func() {
c.mu.Lock()
c.conn = nil
c.mu.Unlock()
c.closeConn()
_ = conn.Close()
// NOTE: streamBufs is intentionally NOT cleared on reconnect.
// Active streams survive reconnections — the WeCom replace-based
@ -707,9 +705,11 @@ func (c *LongConnClient) convertMixedMessage(msg *botMessage, chatID string, cha
// pending ReadMessage call in the receive loop and triggers a reconnection.
func (c *LongConnClient) closeConn() {
c.mu.Lock()
defer c.mu.Unlock()
if c.conn != nil {
_ = c.conn.Close()
conn := c.conn
c.conn = nil
c.mu.Unlock()
if conn != nil {
_ = conn.Close()
}
}