summaryrefslogtreecommitdiff
path: root/core/runtime.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-11-27 14:19:24 +0100
committerGitHub <noreply@github.com>2020-11-27 14:19:24 +0100
commit22f951aa67c5b677d156ec338f71714cf2d4ddb2 (patch)
tree58537dffb4aa0f3c3b2a348c99466cb89919c835 /core/runtime.rs
parent28869a632d190dc29d78738bc5e90eadf99bc824 (diff)
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.
Diffstat (limited to 'core/runtime.rs')
-rw-r--r--core/runtime.rs10
1 files changed, 7 insertions, 3 deletions
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