Files
chenhg5-cc-connect/platform/max
Shawn 4c7145ac23 fix(max): wire async webhook handler ctx to platform Stop() (#991)
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).
2026-05-18 21:38:29 +08:00
..