mirror of
https://github.com/chenhg5/cc-connect.git
synced 2026-07-07 15:12:21 +08:00
webhookHandler spawned a goroutine for each MAX update with the stated intent
that p.Stop() would cancel in-flight handler work:
p.mu.RLock()
ctx := context.Background()
if p.cancel != nil {
ctx2, cancel := context.WithCancel(ctx)
_ = cancel
ctx = ctx2
}
p.mu.RUnlock()
p.handleUpdate(ctx, &upd)
But the derived ctx2 was a child of context.Background(), not of the parent
context that p.cancel cancels — so Stop() never reached the goroutine, the
discarded cancel was never invoked, and downstream cancellable work
(sendChatAction, fetchAttachments, etc.) kept running to completion or
until the per-request HTTP client timeout.
Store the parent context on the platform when Start creates the
WithCancel pair, and read it through a new webhookCtx() helper that
falls back to context.Background() when the platform is not running
(unit tests call webhookHandler directly).