diff options
Diffstat (limited to 'runtime/ops/http.rs')
-rw-r--r-- | runtime/ops/http.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs index 7a58da361..e751adae8 100644 --- a/runtime/ops/http.rs +++ b/runtime/ops/http.rs @@ -1,6 +1,7 @@ use std::cell::RefCell; use std::rc::Rc; +use deno_core::error::bad_resource; use deno_core::error::bad_resource_id; use deno_core::error::custom_error; use deno_core::error::AnyError; @@ -44,8 +45,11 @@ fn op_http_start( .resource_table .take::<TcpStreamResource>(tcp_stream_rid) { + // This TCP connection might be used somewhere else. If it's the case, we cannot proceed with the + // process of starting a HTTP server on top of this TCP connection, so we just return a bad + // resource error. See also: https://github.com/denoland/deno/pull/16242 let resource = Rc::try_unwrap(resource_rc) - .expect("Only a single use of this resource should happen"); + .map_err(|_| bad_resource("TCP stream is currently in use"))?; let (read_half, write_half) = resource.into_inner(); let tcp_stream = read_half.reunite(write_half)?; let addr = tcp_stream.local_addr()?; @@ -56,8 +60,11 @@ fn op_http_start( .resource_table .take::<TlsStreamResource>(tcp_stream_rid) { + // This TLS connection might be used somewhere else. If it's the case, we cannot proceed with the + // process of starting a HTTP server on top of this TLS connection, so we just return a bad + // resource error. See also: https://github.com/denoland/deno/pull/16242 let resource = Rc::try_unwrap(resource_rc) - .expect("Only a single use of this resource should happen"); + .map_err(|_| bad_resource("TLS stream is currently in use"))?; let (read_half, write_half) = resource.into_inner(); let tls_stream = read_half.reunite(write_half); let addr = tls_stream.get_ref().0.local_addr()?; @@ -71,8 +78,11 @@ fn op_http_start( { super::check_unstable(state, "Deno.serveHttp"); + // This UNIX socket might be used somewhere else. If it's the case, we cannot proceed with the + // process of starting a HTTP server on top of this UNIX socket, so we just return a bad + // resource error. See also: https://github.com/denoland/deno/pull/16242 let resource = Rc::try_unwrap(resource_rc) - .expect("Only a single use of this resource should happen"); + .map_err(|_| bad_resource("UNIX stream is currently in use"))?; let (read_half, write_half) = resource.into_inner(); let unix_stream = read_half.reunite(write_half)?; let addr = unix_stream.local_addr()?; |