diff --git a/roles/roles-utils/network-helpers/src/lib.rs b/roles/roles-utils/network-helpers/src/lib.rs index 2879e3ad6..3555c2056 100644 --- a/roles/roles-utils/network-helpers/src/lib.rs +++ b/roles/roles-utils/network-helpers/src/lib.rs @@ -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 for Error { diff --git a/roles/roles-utils/network-helpers/src/noise_connection_async_std.rs b/roles/roles-utils/network-helpers/src/noise_connection_async_std.rs index 0bfad7e9d..ae4052903 100644 --- a/roles/roles-utils/network-helpers/src/noise_connection_async_std.rs +++ b/roles/roles-utils/network-helpers/src/noise_connection_async_std.rs @@ -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): ( diff --git a/roles/roles-utils/network-helpers/src/noise_connection_tokio.rs b/roles/roles-utils/network-helpers/src/noise_connection_tokio.rs index 06a4961be..2e2996365 100644 --- a/roles/roles-utils/network-helpers/src/noise_connection_tokio.rs +++ b/roles/roles-utils/network-helpers/src/noise_connection_tokio.rs @@ -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();