diff options
author | Yusuke Tanaka <yusuktan@maguro.dev> | 2022-10-18 11:28:27 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-18 11:28:27 +0900 |
commit | 44a89dd6dc7864822ddb48d030af519160de90a2 (patch) | |
tree | 3a7fe40040372d6118a86276d7d91317ab026de5 /ext/net/ops_tls.rs | |
parent | 74be01273c16b83b1063da1750045b12e095f0c3 (diff) |
fix(ext/net): return an error from `startTls` and `serveHttp` if the original connection is captured elsewhere (#16242)
This commit removes the calls to `expect()` on `std::rc::Rc`, which caused
Deno to panic under certain situations. We now return an error if `Rc`
is referenced by other variables.
Fixes #9360
Fixes #13345
Fixes #13926
Fixes #16241
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ext/net/ops_tls.rs')
-rw-r--r-- | ext/net/ops_tls.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/ext/net/ops_tls.rs b/ext/net/ops_tls.rs index a1b48b84e..a59cd747e 100644 --- a/ext/net/ops_tls.rs +++ b/ext/net/ops_tls.rs @@ -812,12 +812,16 @@ where .borrow::<DefaultTlsOptions>() .root_cert_store .clone(); + let resource_rc = state .borrow_mut() .resource_table .take::<TcpStreamResource>(rid)?; + // This TCP connection might be used somewhere else. If it's the case, we cannot proceed with the + // process of starting a TLS connection 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)?; |