Skip to content

Commit

Permalink
Fix network helper panic if peer close connection
Browse files Browse the repository at this point in the history
When the remote peer try to open an encrypted sv2 connection and then
immediatly close the tcp connection, the helper for async std and tokio
it panic, mostly of the time we don't want to panic in this situation.
This commit add an error for this case and return it.
  • Loading branch information
fi3 committed May 7, 2024
1 parent f951edd commit 66433cc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions roles/roles-utils/network-helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum Error {
CodecError(CodecError),
RecvError,
SendError,
// This means that a socket that was supposed to be opened have been closed, likley by the peer
SocketClosed,
}

impl From<CodecError> for Error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Connection {
),
Error,
> {
let address = stream.peer_addr().unwrap();
let address = stream.peer_addr().map_err(|_| Error::SocketClosed)?;
let (mut reader, writer) = (stream.clone(), stream.clone());

let (sender_incoming, receiver_incoming): (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Connection {
),
Error,
> {
let address = stream.peer_addr().unwrap();
let address = stream.peer_addr().map_err(|_| Error::SocketClosed)?;

let (mut reader, mut writer) = stream.into_split();

Expand Down

0 comments on commit 66433cc

Please sign in to comment.