Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(s2n-quic-transport): Map poll_accept errors to documented return value #1743

Merged
merged 5 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions quic/s2n-quic-core/src/connection/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,25 @@ impl Error {
let source = panic::Location::caller();
Error::Unspecified { source }
}

#[inline]
#[doc(hidden)]
pub fn into_accept_error(error: connection::Error) -> Result<(), connection::Error> {
match error {
// The connection closed without an error
connection::Error::Closed { .. } => Ok(()),
// The application closed the connection
connection::Error::Transport { code, .. }
if code == transport::Error::APPLICATION_ERROR.code =>
{
Ok(())
}
// The local connection's idle timer expired
connection::Error::IdleTimerExpired { .. } => Ok(()),
// Otherwise return the real error to the user
_ => Err(error),
}
}
}

/// Returns a CONNECTION_CLOSE frame for the given connection Error, if any
Expand Down
9 changes: 7 additions & 2 deletions quic/s2n-quic-transport/src/connection/connection_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use core::{
use s2n_quic_core::{
application,
application::ServerName,
connection::{id::Generator as _, InitialId, PeerId},
connection::{error::Error, id::Generator as _, InitialId, PeerId},
crypto::{tls, CryptoSuite},
datagram::{Receiver, Sender},
event::{
Expand Down Expand Up @@ -1742,7 +1742,12 @@ impl<Config: endpoint::Config> connection::Trait for ConnectionImpl<Config> {
stream_type: Option<stream::StreamType>,
context: &Context,
) -> Poll<Result<Option<stream::StreamId>, connection::Error>> {
self.error?;
if let Err(error) = self.error {
match Error::into_accept_error(error) {
Ok(_) => return Ok(None).into(),
Err(err) => return Err(err).into(),
};
}

let (space, _) = self
.space_manager
Expand Down
22 changes: 8 additions & 14 deletions quic/s2n-quic-transport/src/stream/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ use core::{
};
use futures_core::ready;
use s2n_quic_core::{
ack, endpoint,
ack,
connection::error::Error,
endpoint,
frame::{
stream::StreamRef, DataBlocked, MaxData, MaxStreamData, MaxStreams, ResetStream,
StopSending, StreamDataBlocked, StreamsBlocked,
Expand Down Expand Up @@ -524,19 +526,11 @@ impl<S: StreamTrait> AbstractStreamManager<S> {
return Ok(Some(stream_id)).into();
});

match self.inner.close_reason {
// The connection closed without an error
Some(connection::Error::Closed { .. }) => return Ok(None).into(),
// Translate application closes to end of stream
Some(connection::Error::Transport { code, .. })
if code == transport::Error::APPLICATION_ERROR.code =>
{
return Ok(None).into()
}
// Translate idle timer expiration to end of stream
Some(connection::Error::IdleTimerExpired { .. }) => return Ok(None).into(),
Some(reason) => return Err(reason).into(),
None => {}
if let Some(close_reason) = self.inner.close_reason {
match Error::into_accept_error(close_reason) {
Ok(_) => return Ok(None).into(),
Err(err) => return Err(err).into(),
};
}

// Store the `Waker` for notifying the application if we accept a Stream
Expand Down