Skip to content

Commit 77ae52a

Browse files
authored
Add a 60-second client reconnect (#80)
* Add a 60-second client reconnect This improves reliability in most cases, such as when network errors are not reported immediately to the streaming request client. It's at the expense of a brief blip during every reconnection. But this should hardly be noticeable, assuming real-time RTL, it would affect ~0.2% of interactions. * Remove dbg! * Fix interval
1 parent fc40422 commit 77ae52a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

crates/sshx/src/controller.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Network gRPC client allowing server control of terminals.
22
33
use std::collections::HashMap;
4+
use std::pin::pin;
45

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

25+
/// Interval to automatically reestablish connections.
26+
const RECONNECT_INTERVAL: Duration = Duration::from_secs(60);
27+
2428
/// Handles a single session's communication with the remote server.
2529
pub struct Controller {
2630
origin: String,
@@ -129,6 +133,7 @@ impl Controller {
129133

130134
let mut interval = time::interval(HEARTBEAT_INTERVAL);
131135
interval.set_missed_tick_behavior(MissedTickBehavior::Delay);
136+
let mut reconnect = pin!(time::sleep(RECONNECT_INTERVAL));
132137
loop {
133138
let message = tokio::select! {
134139
_ = interval.tick() => {
@@ -145,6 +150,9 @@ impl Controller {
145150
.server_message
146151
.context("server message is missing")?
147152
}
153+
_ = &mut reconnect => {
154+
return Ok(()); // Reconnect to the server.
155+
}
148156
};
149157

150158
match message {

fly.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
app = "sshx"
22
primary_region = "ewr"
33
kill_signal = "SIGINT"
4-
kill_timeout = 5
4+
kill_timeout = 90
55

66
[experimental]
77
auto_rollback = true

0 commit comments

Comments
 (0)