diff --git a/ext/net/01_net.js b/ext/net/01_net.js index 90a0e5be4d..d1c5f56604 100644 --- a/ext/net/01_net.js +++ b/ext/net/01_net.js @@ -596,7 +596,6 @@ async function connect(args) { hostname: args.hostname ?? "127.0.0.1", port, }, - args.timeout, cancelRid, ); localAddr.transport = "tcp"; diff --git a/ext/net/lib.deno_net.d.ts b/ext/net/lib.deno_net.d.ts index 8bd859b86b..213b90ad26 100644 --- a/ext/net/lib.deno_net.d.ts +++ b/ext/net/lib.deno_net.d.ts @@ -290,7 +290,6 @@ declare namespace Deno { * @default {"127.0.0.1"} */ hostname?: string; transport?: "tcp"; - timeout?: number; signal?: AbortSignal | null; } diff --git a/ext/net/ops.rs b/ext/net/ops.rs index f7e1628d66..3fe5fe84ab 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -36,7 +36,6 @@ use socket2::Socket; use socket2::Type; use std::borrow::Cow; use std::cell::RefCell; -use std::future::Future; use std::net::Ipv4Addr; use std::net::Ipv6Addr; use std::net::SocketAddr; @@ -44,7 +43,6 @@ use std::rc::Rc; use std::str::FromStr; use tokio::net::TcpStream; use tokio::net::UdpSocket; -use tokio::time::timeout; #[derive(Serialize, Clone, Debug)] #[serde(rename_all = "camelCase")] @@ -67,28 +65,6 @@ impl From for IpAddr { } } -pub trait TcpStreamTimeout { - fn connect_timeout( - addr: &SocketAddr, - tcp_timeout: Option, - ) -> impl Future>; -} - -impl TcpStreamTimeout for TcpStream { - async fn connect_timeout( - addr: &SocketAddr, - tcp_timeout: Option, - ) -> Result { - if tcp_timeout.is_none() { - TcpStream::connect(addr).await - } else { - let timeout_duration = - std::time::Duration::from_millis(tcp_timeout.unwrap()); - timeout(timeout_duration, TcpStream::connect(addr)).await? - } - } -} - #[derive(Debug, thiserror::Error)] pub enum NetError { #[error("Listener has been closed")] @@ -372,20 +348,18 @@ pub async fn op_net_set_multi_ttl_udp( pub async fn op_net_connect_tcp( state: Rc>, #[serde] addr: IpAddr, - #[serde] timeout: Option, #[smi] resource_abort_id: Option, ) -> Result<(ResourceId, IpAddr, IpAddr), NetError> where NP: NetPermissions + 'static, { - op_net_connect_tcp_inner::(state, addr, timeout, resource_abort_id).await + op_net_connect_tcp_inner::(state, addr, resource_abort_id).await } #[inline] pub async fn op_net_connect_tcp_inner( state: Rc>, addr: IpAddr, - timeout: Option, resource_abort_id: Option, ) -> Result<(ResourceId, IpAddr, IpAddr), NetError> where @@ -412,13 +386,17 @@ where }); let tcp_stream_result = if let Some(cancel_handle) = &cancel_handle { - TcpStream::connect_timeout(&addr, timeout) - .or_cancel(cancel_handle) - .await? + TcpStream::connect(&addr).or_cancel(cancel_handle).await? } else { - TcpStream::connect_timeout(&addr, timeout).await + TcpStream::connect(&addr).await }; + if let Some(cancel_rid) = resource_abort_id { + if let Ok(res) = state.borrow_mut().resource_table.take_any(cancel_rid) { + res.close(); + } + } + let tcp_stream = match tcp_stream_result { Ok(tcp_stream) => tcp_stream, Err(e) => return Err(NetError::Io(e)), @@ -1175,10 +1153,9 @@ mod tests { port: server_addr[1].parse().unwrap(), }; - let mut connect_fut = op_net_connect_tcp_inner::( - conn_state, ip_addr, None, None, - ) - .boxed_local(); + let mut connect_fut = + op_net_connect_tcp_inner::(conn_state, ip_addr, None) + .boxed_local(); let mut rid = None; tokio::select! { diff --git a/tests/unit/net_test.ts b/tests/unit/net_test.ts index bcd55383c8..d17b6ee643 100644 --- a/tests/unit/net_test.ts +++ b/tests/unit/net_test.ts @@ -1277,22 +1277,6 @@ Deno.test({ } }); -Deno.test( - { permissions: { net: true } }, - async function netTcpSetTimeout() { - try { - const conn = await Deno.connect({ - hostname: "example.com", - port: 50000, - timeout: 1000, - }); - conn.close(); - } catch (error) { - assert(error instanceof Deno.errors.TimedOut); - } - }, -); - Deno.test( { permissions: { net: true } }, async function netTcpWithAbortSignal() {