From 44a89dd6dc7864822ddb48d030af519160de90a2 Mon Sep 17 00:00:00 2001 From: Yusuke Tanaka Date: Tue, 18 Oct 2022 11:28:27 +0900 Subject: fix(ext/net): return an error from `startTls` and `serveHttp` if the original connection is captured elsewhere (#16242) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- core/resources.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'core') diff --git a/core/resources.rs b/core/resources.rs index ee9ee689f..164c377a2 100644 --- a/core/resources.rs +++ b/core/resources.rs @@ -291,6 +291,12 @@ impl ResourceTable { /// If a resource with the given `rid` exists but its type does not match `T`, /// it is not removed from the resource table. Note that the resource's /// `close()` method is *not* called. + /// + /// Also note that there might be a case where + /// the returned `Rc` is referenced by other variables. That is, we cannot + /// assume that `Rc::strong_count(&returned_rc)` is always equal to 1 on success. + /// In particular, be really careful when you want to extract the inner value of + /// type `T` from `Rc`. pub fn take(&mut self, rid: ResourceId) -> Result, Error> { let resource = self.get::(rid)?; self.index.remove(&rid); @@ -299,6 +305,12 @@ impl ResourceTable { /// Removes a resource from the resource table and returns it. Note that the /// resource's `close()` method is *not* called. + /// + /// Also note that there might be a + /// case where the returned `Rc` is referenced by other variables. That is, + /// we cannot assume that `Rc::strong_count(&returned_rc)` is always equal to 1 + /// on success. In particular, be really careful when you want to extract the + /// inner value of type `T` from `Rc`. pub fn take_any( &mut self, rid: ResourceId, -- cgit v1.2.3