Skip to content

Commit

Permalink
Stop mirrord ending unexpectedly when port forwarding in reverse (#2964)
Browse files Browse the repository at this point in the history
* Fix ping/pong routine in ReversePortForwarder

* Add changelog
  • Loading branch information
gememma authored Dec 6, 2024
1 parent 337df2a commit c7efd30
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/2962.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stop mirrord ending unexpectedly when port forwarding in reverse due to unexpected connection end.
5 changes: 4 additions & 1 deletion mirrord/cli/src/port_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ pub struct ReversePortForwarder {

/// true if Ping has been sent to agent.
waiting_for_pong: bool,
ping_pong_timeout: Instant,
}

impl ReversePortForwarder {
Expand Down Expand Up @@ -480,6 +481,7 @@ impl ReversePortForwarder {
background_tasks,
incoming_proxy: incoming,
waiting_for_pong: false,
ping_pong_timeout: Instant::now(),
})
}

Expand Down Expand Up @@ -511,13 +513,14 @@ impl ReversePortForwarder {

loop {
select! {
_ = tokio::time::sleep(Duration::from_secs(30)) => {
_ = tokio::time::sleep_until(self.ping_pong_timeout.into()) => {
if self.waiting_for_pong {
// no pong received before timeout
break Err(PortForwardError::AgentError("agent failed to respond to Ping".into()));
}
self.agent_connection.sender.send(ClientMessage::Ping).await?;
self.waiting_for_pong = true;
self.ping_pong_timeout = Instant::now() + Duration::from_secs(30);
},

message = self.agent_connection.receiver.recv() => match message {
Expand Down

0 comments on commit c7efd30

Please sign in to comment.