Skip to content

Commit

Permalink
refactor: use channel index to reference port shutdown
Browse files Browse the repository at this point in the history
Make use of the channel index to reference the shutdown port index to make it consistent
with the initialized check.
This is because even channel indexes are for data and odd indexes are for errors.

Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Sep 5, 2022
1 parent 751f352 commit 3be996b
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions kube-client/src/api/portforward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,11 @@ where
.map_err(Error::InvalidErrorMessage)?;
sender.send(s).map_err(Error::ForwardErrorMessage)?;
}
} else {
if !chan_state[port_index].shutdown {
writers[port_index]
.write_all(&bytes)
.await
.map_err(Error::WriteBytesFromPod)?;
}
} else if !chan_state[ch].shutdown {
writers[port_index]
.write_all(&bytes)
.await
.map_err(Error::WriteBytesFromPod)?;
}
}

Expand All @@ -335,9 +333,9 @@ where
return Err(Error::InvalidChannel(ch));
}
let port_index = ch / 2;
if !chan_state[port_index].shutdown {
if !chan_state[ch].shutdown {
writers[port_index].shutdown().await.map_err(Error::Shutdown)?;
chan_state[port_index].shutdown = true;
chan_state[ch].shutdown = true;

closed_ports += 1;
}
Expand Down

0 comments on commit 3be996b

Please sign in to comment.