diff options
| author | Liam Murphy <43807659+Liamolucko@users.noreply.github.com> | 2021-04-20 00:57:02 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-19 16:57:02 +0200 |
| commit | 4786e1d92dcbdcbe743c5e2be0878c3c4f68e781 (patch) | |
| tree | 54dfcfd0b9eab77f45f015e9113b21e2a4884f3e /runtime | |
| parent | 776a999eab2b04385ccd2c80cdce365feec20e05 (diff) | |
fix(runtime): handle race condition in postMessage where worker has terminated (#10239)
The panic was caused by the lack of an error class mapping for
futures::channel::TrySendError, but it shouldn't have been throwing an error in
the first place - when a worker has terminated, postMessage should just return.
The issue was that the termination message hadn't yet been recieved, so it was
carrying on with trying to send the message. This adds another check on the Rust
side for if the channel is closed, and if it is the worker is treated as
terminated.
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/web_worker.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 68bbe1a5d..8c8761d62 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -67,6 +67,14 @@ impl WebWorkerHandle { /// Post message to worker as a host. pub fn post_message(&self, buf: Box<[u8]>) -> Result<(), AnyError> { let mut sender = self.sender.clone(); + // If the channel is closed, + // the worker must have terminated but the termination message has not yet been recieved. + // + // Therefore just treat it as if the worker has terminated and return. + if sender.is_closed() { + self.terminated.store(true, Ordering::SeqCst); + return Ok(()); + } sender.try_send(buf)?; Ok(()) } |
