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 the naming of heartbeat_to_dead #12

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions replit_river/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions replit_river/transport_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,39 @@ 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
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()
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""

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":
session_disconnect_grace_ms = float(
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,
)
Loading