Skip to content

Commit

Permalink
fix(igd): Fix the condition for terminating the IGD renewal loop
Browse files Browse the repository at this point in the history
The condition was the wrong way around. The desired behaviour is that
closing an endpoint causes the renewal loop to stop. When an endpoint
is closed, a message (`()`) is sent to the `termination_tx`, which is
connected to the `termination_rx` in the renewal loop. Therefore we want
to break the loop if we *have* received a message, indicating that the
endpoint was closed.

The condition would also terminate the loop on any other error from
`try_recv` (e.g. if the endpoint was dropped), and this has been
preserved.
  • Loading branch information
Chris Connelly authored and lionel-faber committed Jul 2, 2021
1 parent eee4dd5 commit 295626c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/igd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub async fn forward_port(

loop {
let _ = timer.tick().await;
if let Err(TryRecvError::Empty) = termination_rx.try_recv() {
if termination_rx.try_recv() != Err(TryRecvError::Empty) {
break;
}
debug!("Renewing IGD lease for port {}", local_addr);
Expand Down

0 comments on commit 295626c

Please sign in to comment.