Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix firehose client stop #384

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions packages/atproto_firehose/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@
from atproto_client.models.base import ParamsModelBase
from atproto_client.models.common import XrpcError
from atproto_core.exceptions import DAGCBORDecodingError

try:
# new asyncio implementation is available since websockets 13.0
from websockets.asyncio.client import connect as aconnect
except ImportError:
# fallback to the legacy implementation for older versions
from websockets.client import connect as aconnect
from websockets.client import connect as aconnect
from websockets.exceptions import (
ConnectionClosedError,
ConnectionClosedOK,
Expand Down Expand Up @@ -52,13 +46,7 @@

if t.TYPE_CHECKING:
from websockets.client import ClientConnection as SyncWebSocketClient

try:
# new asyncio implementation is available since websockets 13.0
from websockets.asyncio.client import ClientConnection as AsyncConnect
except ImportError:
# fallback to the legacy implementation for older versions
from websockets.legacy.client import Connect as AsyncConnect
from websockets.legacy.client import Connect as AsyncConnect


def _build_websocket_uri(method: str, base_uri: str, params: t.Optional[t.Dict[str, t.Any]] = None) -> str:
Expand Down Expand Up @@ -133,10 +121,10 @@ def _websocket_uri(self) -> str:
return _build_websocket_uri(self._method, self._base_uri, self._params)

def _get_client(self) -> 'SyncWebSocketClient':
return connect(self._websocket_uri, max_size=_MAX_MESSAGE_SIZE_BYTES, close_timeout=None)
return connect(self._websocket_uri, max_size=_MAX_MESSAGE_SIZE_BYTES, close_timeout=0.1)

def _get_async_client(self) -> 'AsyncConnect':
return aconnect(self._websocket_uri, max_size=_MAX_MESSAGE_SIZE_BYTES, close_timeout=None)
return aconnect(self._websocket_uri, max_size=_MAX_MESSAGE_SIZE_BYTES, close_timeout=0.1)

def _get_reconnection_delay(self) -> int:
base_sec = 2**self._reconnect_no
Expand Down
Loading