Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when closing a worker immediately after postMessage #5334

Closed
carlbennettnz opened this issue May 14, 2020 · 4 comments · Fixed by #8510
Closed

Panic when closing a worker immediately after postMessage #5334

carlbennettnz opened this issue May 14, 2020 · 4 comments · Fixed by #8510
Assignees
Labels
bug Something isn't working correctly cli related to cli/ dir

Comments

@carlbennettnz
Copy link

carlbennettnz commented May 14, 2020

// main.js
const worker = new Worker('./worker.js', { type: 'module' });
worker.onmessage = ({ data }) => console.log(data);

// worker.js
self.postMessage('message');
self.close();
$ RUST_BACKTRACE=1 deno run main.js
thread 'deno-worker-0' panicked at 'Failed to post message to host: TrySendError { kind: Disconnected }', cli/ops/worker_host.rs:142:7
stack backtrace:
message
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::result::unwrap_failed
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread 'main' panicked at 'Worker thread panicked: Any', cli/ops/worker_host.rs:329:11
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::result::unwrap_failed
   9: <std::future::GenFuture<T> as core::future::future::Future>::poll
  10: futures_util::future::future::chain::Chain<Fut1,Fut2,Data>::poll
  11: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
  12: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
  13: <&mut S as futures_core::stream::Stream>::poll_next
  14: futures_util::stream::stream::StreamExt::poll_next_unpin
  15: <deno_core::isolate::CoreIsolate as core::future::future::Future>::poll
  16: <deno_core::es_isolate::EsIsolate as core::future::future::Future>::poll
  17: <std::future::GenFuture<T> as core::future::future::Future>::poll
  18: std::thread::local::LocalKey<T>::with
  19: tokio::macros::scoped_tls::ScopedKey<T>::set
  20: tokio::runtime::basic_scheduler::BasicScheduler<P>::block_on
  21: tokio::runtime::context::enter
  22: deno::tokio_util::run_basic
  23: deno::main
  24: std::rt::lang_start::{{closure}}
  25: std::panicking::try::do_call
  26: __rust_maybe_catch_panic
  27: std::rt::lang_start_internal
  28: main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

This works in the browser. Postponing the close until the next tick makes it work in Deno.

self.postMessage('message');
setTimeout(() => self.close(), 0);
@ry ry added the bug Something isn't working correctly label May 14, 2020
@sertsedat
Copy link

sertsedat commented May 14, 2020

awaiting somehow works

// worker.js
await self.postMessage('message');
self.close();

@bartlomieju
Copy link
Member

you have to use await

// worker.js
await self.postMessage('message');
self.close();

postMessage is a synchronous function. This is a bug in implementation

@brandonkal
Copy link
Contributor

This doesn't appear to be related to postMessage
This also fails

// runnter.ts
new Worker(new URL('worker-test.ts', import.meta.url).href, { type: 'module' })

// worker-test.ts
console.log('hello from worker')
self.close()
brandon@dev:~/worker$ RUST_BACKTRACE=1 deno run -A runner.ts
hello from worker
thread 'deno-worker-0' panicked at 'Failed to post message to host: TrySendError { kind: Disconnected }', cli/ops/worker_host.rs:144:7
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1504
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:511
  11: rust_begin_unwind
             at src/libstd/panicking.rs:419
  12: core::panicking::panic_fmt
             at src/libcore/panicking.rs:111
  13: core::option::expect_none_failed
             at src/libcore/option.rs:1268
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread 'main' panicked at 'Worker thread panicked: Any', cli/ops/worker_host.rs:332:11
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1504
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:511
  11: rust_begin_unwind
             at src/libstd/panicking.rs:419
  12: core::panicking::panic_fmt
             at src/libcore/panicking.rs:111
  13: core::option::expect_none_failed
             at src/libcore/option.rs:1268
  14: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
  15: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
  16: <futures_util::future::future::Then<Fut1,Fut2,F> as core::future::future::Future>::poll
  17: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
  18: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
  19: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
  20: futures_util::stream::stream::StreamExt::poll_next_unpin
  21: <deno_core::core_isolate::CoreIsolate as core::future::future::Future>::poll
  22: <deno_core::es_isolate::EsIsolate as core::future::future::Future>::poll
  23: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
  24: std::thread::local::LocalKey<T>::with
  25: tokio::macros::scoped_tls::ScopedKey<T>::set
  26: tokio::runtime::context::enter
  27: deno::tokio_util::run_basic
  28: deno::main
  29: std::rt::lang_start::{{closure}}
  30: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:52
  31: std::panicking::try::do_call
             at src/libstd/panicking.rs:331
  32: std::panicking::try
             at src/libstd/panicking.rs:274
  33: std::panic::catch_unwind
             at src/libstd/panic.rs:394
  34: std::rt::lang_start_internal
             at src/libstd/rt.rs:51
  35: main
  36: __libc_start_main
  37: _start

@ry ry added the cli related to cli/ dir label Jul 8, 2020
@bartlomieju bartlomieju mentioned this issue Oct 10, 2020
22 tasks
@jcc10
Copy link

jcc10 commented Nov 11, 2020

I just wanted to add that this may relate to #7620. I didn't check the panic log for the other one but I felt it best to just cross reference them for future people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly cli related to cli/ dir
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants