From a61e6d4433fd036537db3cf219e618cd34612487 Mon Sep 17 00:00:00 2001 From: "Ian Clarke (aider)" Date: Thu, 26 Dec 2024 16:44:47 -0600 Subject: [PATCH] fix: Resolve future polling and pinning issues in connection handler --- crates/core/src/transport/connection_handler.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/core/src/transport/connection_handler.rs b/crates/core/src/transport/connection_handler.rs index d5903fe5d..cd3bbe5e1 100644 --- a/crates/core/src/transport/connection_handler.rs +++ b/crates/core/src/transport/connection_handler.rs @@ -292,10 +292,12 @@ impl UdpPacketsListener { let span = tracing::span!(tracing::Level::DEBUG, "gateway_connection"); async move { let future = Box::pin(gw_ongoing_connection); - match futures::Future::poll(unsafe { Pin::new_unchecked(&mut future) }, &mut std::task::Context::from_waker(futures::task::noop_waker_ref())) { + match futures::Future::poll(Box::pin(&mut future).as_mut(), &mut std::task::Context::from_waker(futures::task::noop_waker_ref())) { std::task::Poll::Ready(Ok(result)) => Ok(result), std::task::Poll::Ready(Err(error)) => Err((error, remote_addr)), - std::task::Poll::Pending => Ok(result) + std::task::Poll::Pending => Err((TransportError::ConnectionEstablishmentFailure { + cause: "Future not ready".into() + }, remote_addr)) } } .instrument(span) @@ -384,10 +386,12 @@ impl UdpPacketsListener { let span = span!(tracing::Level::DEBUG, "traverse_nat"); async move { let future = Box::pin(ongoing_connection); - match futures::Future::poll(unsafe { Pin::new_unchecked(&mut future) }, &mut std::task::Context::from_waker(futures::task::noop_waker_ref())) { + match futures::Future::poll(Box::pin(&mut future).as_mut(), &mut std::task::Context::from_waker(futures::task::noop_waker_ref())) { std::task::Poll::Ready(Ok(result)) => Ok(result), std::task::Poll::Ready(Err(error)) => Err((error, remote_addr)), - std::task::Poll::Pending => Ok(result) + std::task::Poll::Pending => Err((TransportError::ConnectionEstablishmentFailure { + cause: "Future not ready".into() + }, remote_addr)) } } .instrument(span)