Skip to content

CancelledError when running on apify infrastructure #309

@krasnoludkolo

Description

@krasnoludkolo

Hello.
I'm running my actors on apify infrastructure and low % of runs ends with:

  Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 1289, in close_connection
    await self.transfer_data_task
  File "/usr/local/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 966, in transfer_data
    await asyncio.shield(self._put_message_waiter)
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/apify/event_manager.py", line 222, in _process_platform_messages
    async for message in websocket:
  File "/usr/local/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 494, in __aiter__
    yield await self.recv()
          ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 564, in recv
    await self.ensure_open()
  File "/usr/local/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 940, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: sent 1011 (internal error) keepalive ping timeout; no close frame received

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/app/src/main.py", line 24, in main
    async with Actor:
  File "/usr/local/lib/python3.11/site-packages/apify/actor.py", line 65, in __aexit__
    await Actor.exit()
  File "/usr/local/lib/python3.11/site-packages/apify/actor.py", line 318, in exit
    return await cls._get_default_instance().exit(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/apify/actor.py", line 352, in _exit_internal
    await self._event_manager.close(event_listeners_timeout_secs=event_listeners_timeout_secs)
  File "/usr/local/lib/python3.11/site-packages/apify/event_manager.py", line 90, in close
    await self._process_platform_messages_task
  File "/usr/local/lib/python3.11/site-packages/apify/event_manager.py", line 236, in _process_platform_messages
    self._connected_to_platform_websocket.set_result(False)
asyncio.exceptions.InvalidStateError: invalid state

I'm using 2.0.0 version, however issue was observed on 1.x.x as well

Is there anything I can do about it?

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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions