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

Add a 60-second client reconnect #80

Merged
merged 3 commits into from
Apr 6, 2024
Merged
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
8 changes: 8 additions & 0 deletions crates/sshx/src/controller.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Network gRPC client allowing server control of terminals.

use std::collections::HashMap;
use std::pin::pin;

use anyhow::{Context, Result};
use sshx_core::proto::{
Expand All @@ -21,6 +22,9 @@ use crate::runner::{Runner, ShellData};
/// Interval for sending empty heartbeat messages to the server.
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(2);

/// Interval to automatically reestablish connections.
const RECONNECT_INTERVAL: Duration = Duration::from_secs(60);

/// Handles a single session's communication with the remote server.
pub struct Controller {
origin: String,
Expand Down Expand Up @@ -129,6 +133,7 @@ impl Controller {

let mut interval = time::interval(HEARTBEAT_INTERVAL);
interval.set_missed_tick_behavior(MissedTickBehavior::Delay);
let mut reconnect = pin!(time::sleep(RECONNECT_INTERVAL));
loop {
let message = tokio::select! {
_ = interval.tick() => {
Expand All @@ -145,6 +150,9 @@ impl Controller {
.server_message
.context("server message is missing")?
}
_ = &mut reconnect => {
return Ok(()); // Reconnect to the server.
}
};

match message {
Expand Down
2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
app = "sshx"
primary_region = "ewr"
kill_signal = "SIGINT"
kill_timeout = 5
kill_timeout = 90

[experimental]
auto_rollback = true
Expand Down
Loading