Skip to content

Commit

Permalink
fix listening to the same port again after closing. (#1551)
Browse files Browse the repository at this point in the history
  • Loading branch information
t4lz authored Jun 13, 2023
1 parent 59254db commit 4d0490a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/1526.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mirroring/stealing a port for a second time after the user application closed it once.
6 changes: 4 additions & 2 deletions mirrord/layer/src/tcp_mirror.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ impl TcpHandler for TcpMirrorHandler {
self.apply_port_mapping(&mut listen);
let request_port = listen.requested_port;

if !self.ports_mut().insert(listen) {
info!("Port {request_port} already listening, might be on different address",);
if self.ports_mut().replace(listen).is_some() {
// This can also be because we currently don't inform the tcp handler when an app closes
// a socket (stops listening).
info!("Received listen hook message for port {request_port} while already listening. Might be on different address",);
return Ok(());
}

Expand Down
6 changes: 4 additions & 2 deletions mirrord/layer/src/tcp_steal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ impl TcpHandler for TcpStealHandler {
self.apply_port_mapping(&mut listen);
let request_port = listen.requested_port;

if !self.ports_mut().insert(listen) {
info!("Port {request_port} already listening, might be on different address");
if self.ports_mut().replace(listen).is_some() {
// This can also be because we currently don't inform the tcp handler when an app closes
// a socket (stops listening).
info!("Received listen hook message for port {request_port} while already listening. Might be on different address",);
return Ok(());
}

Expand Down

0 comments on commit 4d0490a

Please sign in to comment.