WeKnora/internal
养乐多 baada32cb6 fix(im/feishu): actually close WebSocket long connection when channel is stopped
Deleting or disabling a Feishu channel left its WebSocket long connection
alive: the Lark SDK's Start blocks on a bare select{} and never observes
ctx, and v3.6.1 exposed no public Close(), so the wsCancel() cleanup was a
no-op. The socket stayed open, the SDK kept auto-reconnecting, and Feishu
kept pushing messages — causing cross-environment message duplication when
the same bot was bound elsewhere.

Fix in three layers:

1. Connection teardown
   - Upgrade oapi-sdk-go v3.6.1 -> v3.9.7 (adds Client.Close()).
   - Add LongConnClient.Close() wrapping wsClient.Close(); factory's cleanup
     now calls Close() first, then wsCancel() as a belt-and-braces fallback.

2. Multi-instance coordination
   - wsLeaderRetryLoop: after acquiring leadership, re-check the DB before
     starting; abort if the channel was deleted/disabled while waiting.
   - wsLeaderRenewLoop: on each renewal, re-check the DB; step down if the
     channel was deleted/disabled on another instance (HTTP request may have
     been served elsewhere), so the leader doesn't keep the connection open
     until process restart.

3. Robustness
   - DB checks distinguish gorm.ErrRecordNotFound (channel truly gone ->
     stop/abort) from transient DB errors (skip this round, retry next tick)
     so a DB hiccup can't cause a spurious stop or permanent leader-abort.
   - startChannelInternal now stops any existing channelState for the same
     ID before overwriting, making it idempotent against concurrent start
     paths and preventing adapter/long-connection leaks.

No interface changes; webhook and long-poll modes unaffected.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-06 23:10:45 +08:00
..
agent fix lint and test failures 2026-07-01 17:31:42 +08:00
application fix(server): case-insensitive doc keyword search + not-found classification 2026-07-06 22:53:01 +08:00
assets feat(assets): add ASR test audio file and embed it in the application 2026-04-02 21:27:27 +08:00
common fix(redis): harden TLS tests and surface TLS config at startup 2026-07-06 23:04:52 +08:00
config test: add document process task options tests 2026-05-28 20:27:53 +08:00
container feat(redis): support TLS for Redis connections (#1930) 2026-07-06 23:02:02 +08:00
database feat(system-info): surface DB migration errors with troubleshooting links 2026-05-14 16:34:50 +08:00
datasource fix(security): close remaining GHSA gaps from security triage 2026-07-02 15:03:53 +08:00
errors feat(knowledge): track per-stage parsing progress with /stages API 2026-05-28 15:14:45 +08:00
event feat(mcp): prompt and resume OAuth authorization mid-conversation 2026-06-29 23:22:28 +08:00
handler fix(server): case-insensitive doc keyword search + not-found classification 2026-07-06 22:53:01 +08:00
im fix(im/feishu): actually close WebSocket long connection when channel is stopped 2026-07-06 23:10:45 +08:00
infrastructure fix(security): redact IM list credentials and harden MinerU SSRF 2026-07-02 17:58:20 +08:00
logger feat(embed): scope OAuth and sessions per visitor principal 2026-06-30 20:01:05 +08:00
mcp feat(im): include per-service MCP OAuth URLs in IM auth notices 2026-07-01 17:53:54 +08:00
middleware fix(server): case-insensitive doc keyword search + not-found classification 2026-07-06 22:53:01 +08:00
models fix(security): harden model client redirects 2026-07-02 19:15:46 +08:00
ratelimit feat(embed): add backend embed channels with auth and rate limiting (#1657) 2026-06-12 23:10:39 +08:00
router feat(redis): support TLS for Redis connections (#1930) 2026-07-06 23:02:02 +08:00
runtime fix(redis): harden TLS tests and surface TLS config at startup 2026-07-06 23:04:52 +08:00
sandbox perf(sandbox): compile command-substitution regexps once 2026-06-16 19:51:32 +08:00
searchutil feat(backend): improve parent-child chunk merge and imageinfo matching 2026-06-16 01:09:07 +08:00
stream feat(redis): support TLS for Redis connections (#1930) 2026-07-06 23:02:02 +08:00
tracing/langfuse feat(observability): enhance Langfuse retrieve and rerank tracing 2026-06-16 01:09:23 +08:00
types fix(security): block refresh tokens as bearer and sandbox MCP uploads 2026-07-02 17:08:17 +08:00
utils fix(security): harden outbound requests and file previews 2026-07-02 19:15:46 +08:00