From f75af3b890992877da349dd8d739bc32af7d147b Mon Sep 17 00:00:00 2001 From: zhenthebuilder Date: Thu, 2 May 2024 13:05:13 -0700 Subject: [PATCH 1/2] Update --- replit_river/session.py | 5 +---- replit_river/transport_options.py | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/replit_river/session.py b/replit_river/session.py index 895d94c..170e3d4 100644 --- a/replit_river/session.py +++ b/replit_river/session.py @@ -267,10 +267,7 @@ async def _heartbeat( ACK_BIT, ) self._heartbeat_misses += 1 - if ( - self._heartbeat_misses - >= self._transport_options.heartbeats_until_dead - ): + if self._heartbeat_misses >= self._transport_options.heartbeats_to_dead: logging.debug( "%r closing websocket because of heartbeat misses", self.session_id, diff --git a/replit_river/transport_options.py b/replit_river/transport_options.py index 39906f3..5adf81e 100644 --- a/replit_river/transport_options.py +++ b/replit_river/transport_options.py @@ -21,7 +21,7 @@ class ConnectionRetryOptions(BaseModel): class TransportOptions(BaseModel): session_disconnect_grace_ms: float = 5_000 heartbeat_ms: float = 500 - heartbeats_until_dead: int = 2 + heartbeats_to_dead: int = 2 use_prefix_bytes: bool = False close_session_check_interval_ms: float = 100 connection_retry_options: ConnectionRetryOptions = ConnectionRetryOptions() @@ -31,7 +31,7 @@ def get_prefix_bytes(self) -> bytes: return PID2_PREFIX_BYTES if self.use_prefix_bytes else b"" def websocket_disconnect_grace_ms(self) -> float: - return self.heartbeat_ms * self.heartbeats_until_dead + return self.heartbeat_ms * self.heartbeats_to_dead @classmethod def create_from_env(cls) -> "TransportOptions": @@ -39,9 +39,9 @@ def create_from_env(cls) -> "TransportOptions": os.getenv("SESSION_DISCONNECT_GRACE_MS", 5_000) ) heartbeat_ms = float(os.getenv("HEARTBEAT_MS", 2000)) - heartbeats_to_dead = int(os.getenv("HEARTBEATS_UNTIL_DEAD", 2)) + heartbeats_to_dead = int(os.getenv("HEARTBEATS_TO_DEAD", 2)) return TransportOptions( session_disconnect_grace_ms=session_disconnect_grace_ms, heartbeat_ms=heartbeat_ms, - heartbeats_until_dead=heartbeats_to_dead, + heartbeats_to_dead=heartbeats_to_dead, ) From 46aeda164c41ff7e7f9cc64c44635c8e8e010561 Mon Sep 17 00:00:00 2001 From: zhenthebuilder Date: Thu, 2 May 2024 13:08:55 -0700 Subject: [PATCH 2/2] Fix --- replit_river/transport_options.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/replit_river/transport_options.py b/replit_river/transport_options.py index 5adf81e..79d461a 100644 --- a/replit_river/transport_options.py +++ b/replit_river/transport_options.py @@ -15,6 +15,9 @@ class ConnectionRetryOptions(BaseModel): budget_restore_interval_ms: float = 200 max_retry: int = 10 + class Config: + validate_assignment = True + # setup in replit web can be found at # https://github.com/replit/repl-it-web/blob/main/pkg/pid2/src/entrypoints/protocol.ts#L13 @@ -27,6 +30,9 @@ class TransportOptions(BaseModel): connection_retry_options: ConnectionRetryOptions = ConnectionRetryOptions() buffer_size: int = 1_000 + class Config: + validate_assignment = True + def get_prefix_bytes(self) -> bytes: return PID2_PREFIX_BYTES if self.use_prefix_bytes else b""