Skip to content

Reconnect to platform events websocket after connection drop #642

Description

@vdusek

Summary

PlatformEventManager.createWebSocketConnection (src/platform_event_manager.ts) connects to the platform events websocket exactly once. On any close it just logs a debug message and drops the socket — it never reconnects. The connection should be re-established after a drop, mirroring the Python SDK fix in apify/apify-sdk-python#967.

Motivation

This websocket is the only channel for platform events (systemInfo, migrating, aborting, and the platform-driven persistState). It can be dropped mid-run without the Actor process itself failing, e.g.:

  • a transient network blip between the container and apify-worker (TCP reset, packet loss) → abnormal close (1006);
  • an idle timeout on an intermediate proxy / load balancer;
  • a ping/pong keepalive timeout;
  • a worker restart / migration → clean close (1012/1001).

When that happens today, the Actor silently stops receiving all platform events for the rest of the run. The worst consequence: a later migrating/aborting is missed, so persistState never fires and in-progress state is lost before migration. Autoscaling also loses the systemInfo signal.

Reconnecting fixes this. Close codes signalling a permanent condition should not be retried (1008 policy violation — unknown/missing run ID or per-run connection limit — plus protocol/data errors 1002/1003/1007/1010).

Reference

See the Python implementation for the approach (reconnect loop with backoff on failed attempts, fail-fast before the first successful connect, non-retryable close-code handling): apify/apify-sdk-python#967.


🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    t-toolingIssues with this label are in the ownership of the tooling team.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions