chenhg5/cc-connect · error

weixin: platform stopped

Error message

weixin: platform stopped

What it means

Start registers the message handler and launches the long-poll loop. If the platform has already been asked to stop (p.stopping is set by Stop), Start refuses to run and returns this sentinel error instead of spawning a new poll loop.

Source

Thrown at platform/weixin/weixin.go:417

	}
	return true
}

func (p *Platform) pauseSession(d time.Duration) {
	if d <= 0 {
		d = time.Hour
	}
	p.pauseMu.Lock()
	p.pauseUntil = time.Now().Add(d)
	p.pauseMu.Unlock()
	slog.Warn("weixin: session paused after gateway error", "duration", d, "account", p.accountLabel)
}

func (p *Platform) Start(handler core.MessageHandler) error {
	p.mu.Lock()
	defer p.mu.Unlock()
	if p.stopping {
		return fmt.Errorf("weixin: platform stopped")
	}
	p.handler = handler
	ctx, cancel := context.WithCancel(context.Background())
	p.cancel = cancel
	go p.pollLoop(ctx)
	return nil
}

// SetLifecycleHandler registers a handler that will be notified once the ilink
// long-poll has confirmed a working session. Implements
// core.AsyncRecoverablePlatform so the engine waits for the actual
// ready-for-poll signal before logging "platform ready" and initialising
// platform-level capabilities.
func (p *Platform) SetLifecycleHandler(h core.PlatformLifecycleHandler) {
	p.mu.Lock()
	defer p.mu.Unlock()
	p.lifecycleHandler = h
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Create a fresh Platform via weixin.New() instead of re-Starting a stopped one
  2. Reorder logic so Start is never called after Stop on the same instance
  3. Guard restarts with the error and rebuild/reconfigure before retrying

Example fix

// before
p.Stop()
p.Start(handler) // fails: platform stopped
// after
p.Stop()
p, err := weixin.New(opts)
if err != nil { return err }
return p.Start(handler)
Defensive patterns

Strategy: type-guard

Validate before calling

// track lifecycle before calling
if platformAlreadyStopped {
    return errors.New("recreate platform instead of restarting")
}

Try / catch

if err := p.Start(handler); err != nil && err.Error() == "weixin: platform stopped" {
    np, nerr := weixin.New(opts)
    if nerr != nil { return nerr }
    return np.Start(handler)
}

Prevention

When it happens

Trigger: Calling Start(handler) after Stop() was called on the same Platform instance, or racing Start against a concurrent Stop that flips p.stopping first.

Common situations: Restart logic that reuses the old platform object instead of constructing a new one via New(); engine shutdown calls Stop then a late reconnect attempts Start on the same instance; tests tearing down and restarting without rebuilding the platform.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/27d6ac0ffdc67fc8. Report an issue: GitHub.