chenhg5/cc-connect · error

cloud_web: platform stopped

Error message

cloud_web: platform stopped

What it means

Platform.Start refuses to run when the platform is already stopping (Stop was called or is in progress). Starting a message handler on a shutting-down platform is rejected to avoid racing teardown: it would create a new context whose cancellation ownership conflicts with Stop.

Source

Thrown at platform/cloud-web/cloudweb.go:171

	}
	return 0
}

func (p *Platform) Name() string { return p.name }

func (p *Platform) SetLifecycleHandler(h core.PlatformLifecycleHandler) {
	p.lifecycleHandler = h
}

func (p *Platform) SetCardNavigationHandler(h core.CardNavigationHandler) {
	p.navHandler = h
}

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

	if ws, ok := p.tp.(*wsTransport); ok {
		ws.onConnected = p.notifyReady
		ws.onDisconnected = p.notifyUnavailable
	}

	if err := p.tp.Start(ctx, p.handleWire); err != nil {
		cancel()
		return err
	}

	// WebSocket connects asynchronously; readiness is signaled after register_ack.
	if _, isWS := p.tp.(*wsTransport); !isWS {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Create a new Platform instance via New after Stop; Platform is single-use across start/stop cycles
  2. Guard the start/stop sequence so Stop cannot run while Start is pending (serialize with your own mutex or lifecycle state machine)
  3. Check logs for a concurrent Stop call (engine shutdown) and delay/retry Start after full shutdown completes, using a fresh instance

Example fix

// before
p.Stop()
err := p.Start(handler) // error: platform stopped

// after
p.Stop()
p, err := cloudweb.New(cfg...)
if err != nil { return err }
err = p.Start(handler)
Defensive patterns

Strategy: try-catch

Validate before calling

// track lifecycle yourself
if p.IsStopped() {
    p, err = cloudweb.New(cfg...) // recreate before starting
}

Try / catch

if err := p.Start(handler); err != nil {
    if strings.Contains(err.Error(), "platform stopped") {
        p, err = cloudweb.New(cfg...)
        if err == nil { err = p.Start(handler) }
    }
    return err
}

Prevention

When it happens

Trigger: Calling p.Start(handler) after p.Stop() has been invoked, or concurrently while another goroutine is inside Stop (stopping flag set under p.mu).

Common situations: Engine restart/reconnect logic that recreates the handler without recreating the Platform; a graceful-shutdown path that races with an auto-reconnect loop; tests reusing a platform instance across subtests after teardown.

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/97a05e50f68ea4fb. Report an issue: GitHub.