Skip to content

Commit 24d874a

Browse files
fix(cable): preserve I/O error kind on the WebSocket data channel (#218)
Map tungstenite::Error::Io to TransportError::IoError(kind), matching the L2capDataChannel variant so the CableDataChannel trait differentiates failure modes regardless of transport. Treat Error::ConnectionClosed as a clean close in recv.
1 parent 700e262 commit 24d874a

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

libwebauthn/src/transport/cable/data_channel.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use async_trait::async_trait;
33
use futures::{SinkExt, StreamExt};
44
use tokio::net::TcpStream;
5-
use tokio_tungstenite::tungstenite::Message;
5+
use tokio_tungstenite::tungstenite::{Error, Message};
66
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
77
use tracing::error;
88

@@ -41,7 +41,10 @@ impl CableDataChannel for WebSocketDataChannel {
4141
.await
4242
.map_err(|e| {
4343
error!(?e, "Failed to send WebSocket message");
44-
TransportError::ConnectionFailed
44+
match e {
45+
Error::Io(io) => TransportError::IoError(io.kind()),
46+
_ => TransportError::ConnectionFailed,
47+
}
4548
})
4649
}
4750

@@ -50,11 +53,17 @@ impl CableDataChannel for WebSocketDataChannel {
5053
match self.stream.next().await {
5154
Some(Ok(Message::Binary(data))) => return Ok(Some(data.into())),
5255
Some(Ok(Message::Ping(_) | Message::Pong(_))) => continue,
53-
Some(Ok(Message::Close(_))) | None => return Ok(None),
56+
Some(Ok(Message::Close(_))) | None | Some(Err(Error::ConnectionClosed)) => {
57+
return Ok(None)
58+
}
5459
Some(Ok(other)) => {
5560
error!(?other, "Unexpected WebSocket message type");
5661
return Err(TransportError::ConnectionFailed);
5762
}
63+
Some(Err(Error::Io(e))) => {
64+
error!(?e, "Failed to read WebSocket message");
65+
return Err(TransportError::IoError(e.kind()));
66+
}
5867
Some(Err(e)) => {
5968
error!(?e, "Failed to read WebSocket message");
6069
return Err(TransportError::ConnectionFailed);

0 commit comments

Comments
 (0)