From 22f951aa67c5b677d156ec338f71714cf2d4ddb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 27 Nov 2020 14:19:24 +0100 Subject: fix: panic in worker when closing at top level (#8510) Fixes panic occurring in worker when "self.close()" is called at the top level, ie. worker shuts down while module evaluation promise hasn't yet resolved. --- core/runtime.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/runtime.rs b/core/runtime.rs index 873167388..7f71af09a 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -901,9 +901,13 @@ impl JsRuntime { let mut receiver = self.mod_evaluate_inner(id)?; poll_fn(|cx| { - if let Poll::Ready(result) = receiver.poll_next_unpin(cx) { - debug!("received module evaluate"); - return Poll::Ready(result.unwrap()); + if let Poll::Ready(maybe_result) = receiver.poll_next_unpin(cx) { + debug!("received module evaluate {:#?}", maybe_result); + // If `None` is returned it means that runtime was destroyed before + // evaluation was complete. This can happen in Web Worker when `self.close()` + // is called at top level. + let result = maybe_result.unwrap_or(Ok(())); + return Poll::Ready(result); } let _r = self.poll_event_loop(cx)?; Poll::Pending -- cgit v1.2.3