Skip to content

asyncio.InvalidStateError in PlatformEventManager._process_platform_messages on websocket disconnection #877

@11a55an

Description

@11a55an

When the actor's websocket connection to the platform drops or times out (e.g., during actor migration or shutdown), the background task crashes with an unhandled asyncio.InvalidStateError.

This occurs because the exception handler inside PlatformEventManager._process_platform_messages attempts to call .set_result(False) on the self._connected_to_platform_websocket Future. However, because this Future was already resolved with True when the connection was initially established, calling .set_result() a second time raises an InvalidStateError which propagates unhandled and crashes the task.

Steps to reproduce the behavior:

  • Run an Actor using the Python SDK.
  • Trigger a platform websocket disconnect, such as a keepalive timeout (websockets.exceptions.ConnectionClosedError) or by migrating the Actor.
  • Observe the unhandled InvalidStateError in the logs as the SDK attempts to set the Future result to False.

The SDK should handle the websocket error gracefully without raising a secondary InvalidStateError. The Future should be checked to see if it is already resolved before attempting to set a new result.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working.t-toolingIssues with this label are in the ownership of the tooling team.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions