ruvnet/RuView · error · Error

Cannot get connection stats for reconnection

Error message

Cannot get connection stats for reconnection

What it means

Thrown by PoseService.reconnectStream() when wsService.getConnectionStats(this.streamConnection) returns null. getConnectionStats (ui/services/websocket.service.js:588) returns null only when findConnectionById cannot find the id in the WebSocketService connection registry, so this error means the pose service holds a stale handle to a connection that was already closed, purged, or never registered.

Source

Thrown at ui/services/pose.service.js:715

        error: error.message,
        connectionState: this.connectionState,
        lastUpdate: this.performanceMetrics.lastUpdateTime
      };
    }
  }

  // Force reconnection
  async reconnectStream() {
    if (!this.streamConnection) {
      throw new Error('No active stream connection to reconnect');
    }

    this.logger.info('Forcing stream reconnection');
    
    // Get current connection stats to preserve options
    const stats = wsService.getConnectionStats(this.streamConnection);
    if (!stats) {
      throw new Error('Cannot get connection stats for reconnection');
    }

    // Extract original options from URL parameters
    const url = new URL(stats.url);
    const params = Object.fromEntries(url.searchParams);
    
    const options = {
      zoneIds: params.zone_ids ? params.zone_ids.split(',') : undefined,
      minConfidence: params.min_confidence ? parseFloat(params.min_confidence) : undefined,
      maxFps: params.max_fps ? parseInt(params.max_fps) : undefined,
      token: params.token
    };

    // Stop current stream
    this.stopPoseStream();

    // Start new stream with same options
    return this.startPoseStream(options);

View on GitHub (pinned to 4685618388)

Solutions

  1. Check the connection still exists before reconnecting: wsService.getActiveConnections().some(c => c.id === this.streamConnection)
  2. Store the original stream options on PoseService inside startPoseStream() and reuse them for reconnect instead of re-parsing them from the connection URL
  3. If the connection is gone, fall back to startPoseStream(lastStreamOptions) instead of throwing
  4. Clear this.streamConnection in stopPoseStream()/dispose() so the earlier 'No active stream connection' guard at line 706 fires instead

Example fix

// before
const stats = wsService.getConnectionStats(this.streamConnection);
if (!stats) {
  throw new Error('Cannot get connection stats for reconnection');
}
const url = new URL(stats.url);
// ...

// after (in startPoseStream): this.lastStreamOptions = options;
async reconnectStream() {
  if (!this.streamConnection) {
    throw new Error('No active stream connection to reconnect');
  }
  const stats = wsService.getConnectionStats(this.streamConnection);
  if (!stats) {
    this.logger.warn('Stream connection no longer registered; restarting from stored options');
    return this.startPoseStream(this.lastStreamOptions);
  }
  // ...parse options from stats.url...
}
Defensive patterns

Strategy: validation

Validate before calling

// Before calling reconnectStream(), confirm the connection is still registered
const isActive = wsService
  .getActiveConnections()
  .some((c) => c.id === poseService.streamConnection);
if (!isActive) {
  // connection already gone: restart from last-known options instead of reconnecting
  return poseService.startPoseStream(lastStreamOptions);
}
await poseService.reconnectStream();

Type guard

/** True when the stored stream connection id is still live in the WS registry. */
function isLiveConnection(wsService, connectionId) {
  return Boolean(connectionId) && wsService.getConnectionStats(connectionId) !== null;
}

Prevention

When it happens

Trigger: Calling reconnectStream() after the underlying WebSocket dropped and WebSocketService removed it from its connections map; calling it after stopPoseStream()/dispose() already tore the connection down; racing the service's own automatic reconnection which closed and re-registered the socket under a new id; module/HMR reload clearing the ws registry while pose.service's singleton survived.

Common situations: UI reconnect button clicked after the server closed the socket; double-click on reconnect; dev-time hot reload leaving stale ids; stream stopped by an error handler but streamConnection not cleared.

Related errors


AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16). Data as JSON: /api/errors/f51c3be1e4c3c1e2. Report an issue: GitHub.