primoze
primoze8mo ago

Segfault when creating second rust MainWorker in program

Hello. Not sure if this is the place to ask since it seems to be a v8 issue (or perhaps an issue with the bindings), but I figured at least people here can point me in the right direction. I have a segfault issue after updating deno_runtime from 0.122.0 to 0.131.0 (deno_core 0.199.0 to 0.229.0). My program segfaults when starting a second worker after the first one has completed, and on a different thread. Running in valgrind it doesn't crash, but it does print a few ==419765== Warning: set address range perms: large range [0x120f7000, 0x32136000) (noaccess), but as far as I can figure out this is just a log for valgrind developers. Using gdb with a core dump I narrowed down the issue to v8::internal::Heap::SetUpSpaces(v8::internal::LinearAllocationArea&, v8::internal::LinearAllocationArea&), but I'm wondering if I'm doing something wrong to be hitting this issue, or if someone else has encountered this. IIRC the last few versions of deno_core have the same v8 version (0.81.0), so it seems strange that nobody encountered this before if I'm doing everything right. I have a minimal reproducible example here: https://github.com/primoze/set-up-spaces I haven't found anything regarding SetUpSpaces searching online, so I thought I'd ask here.
GitHub
GitHub - primoze/set-up-spaces: Minimal reproducible example for de...
Minimal reproducible example for deno/v8 segfault. Contribute to primoze/set-up-spaces development by creating an account on GitHub.
9 Replies
Deno AI Helper
Deno AI Helper8mo ago
I'm sorry to hear that you're experiencing a segfault issue. Based on the documentation, Deno does support the use of Workers, which can be used to run code on multiple threads. Each instance of Worker is run on a separate thread, dedicated only to that worker. However, there are some specific ways to create a worker in Deno. Here is the recommended way to create a worker:
new Worker(new URL("./worker.js", import.meta.url).href, { type: "module" });
new Worker(new URL("./worker.js", import.meta.url).href, { type: "module" });
And here are some examples that are not recommended:
new Worker(new URL("./worker.js", import.meta.url).href);
new Worker(new URL("./worker.js", import.meta.url).href, { type: "classic" });
new Worker("./worker.js", { type: "module" });
new Worker(new URL("./worker.js", import.meta.url).href);
new Worker(new URL("./worker.js", import.meta.url).href, { type: "classic" });
new Worker("./worker.js", { type: "module" });
If you're not creating the workers in the recommended way, this could potentially be causing the issue. Also, it's important to note that Workers currently do not work in compiled executables. If you're trying to use Workers in a compiled executable, this could be the source of the problem. If you're still experiencing the issue after checking these points, it might be helpful to debug the issue further. Deno has built-in debugger capabilities that make it possible to use remote debuggers like Chrome Devtools or the VSCode builtin debugger. These tools can be extremely useful when trying to pin-point bugs. If you're still unable to resolve the issue, it might be best to open an issue on the Deno GitHub repository to get help from the Deno community. 🦕
primoze
primoze7mo ago
My problem is not caused by JS workers, but by deno_runtime::workers::MainWorker being initialized in rust code. It'd be great if a human could take a look at this... The issue starts occurring when upgrading from 0.129.0 to 0.130.0 (v8 0.79,2 to 0.81.0)
marianoguerra
marianoguerra7mo ago
hi, I have a reproduction repo that may be related, if I reload a module it segfaults if I keep a reference to the worker but it doesn't if I don't. The repo is here: https://github.com/marianoguerra-atik/deno-runtime-segfault
GitHub
GitHub - marianoguerra-atik/deno-runtime-segfault: reproduction of ...
reproduction of issue. Contribute to marianoguerra-atik/deno-runtime-segfault development by creating an account on GitHub.
marvinh.
marvinh.7mo ago
the runtime folks hang out more in #dev-core or #dev-rusty_v8 than here
primoze
primoze7mo ago
Note: since V8 11.6, all runtimes must have a common parent thread that initalized the V8 platform. this solved the issue, but as far as I can tell there are versions with v8 > 11.6 which don't have the issue
marianoguerra
marianoguerra7mo ago
@primoze how do you initialize v8?
primoze
primoze7mo ago
let platform = v8::new_default_platform(0, false).make_shared();
deno_runtime::deno_core::JsRuntime::init_platform(Some(platform));
let platform = v8::new_default_platform(0, false).make_shared();
deno_runtime::deno_core::JsRuntime::init_platform(Some(platform));
primoze
primoze7mo ago
this is just from the example at https://docs.rs/v8/latest/v8/
v8 - Rust
Example
primoze
primoze7mo ago
i need to read up on Platform also this only solves the issue in my repro example, in my actual app it segfaults even earlier now, when creating the first worker. maybe the issue is that i initialize the plaform in tokio::main (so inside a runtime), i need to shuffle some code around and so that it doesn't happen inside a runtime and see if it works yup, that was the issue
More Posts
How can I use "Logging with colors" with `"npm:log-update"`Hi https://examples.deno.land/color-logging I don't want to use Chalk because it's not properly typeHow to uploading images from frontend to Deno.serve()Hey, can someone please give me a vanilla code example on how to upload files from my frontend applDeno Deploy JSON importI'm using zod-i18n-map library for error translation, which requires an import for the library itselMost efficient way to broadcast messages globally across main script and workers?I basically want a simple message bus that is global to all my workers + the main script, without reWhat is the process for deploying a jupyter notebook made using deno?I have webdev experience and was using Observable. I was looking for alternatives that use javascripPostGraphile on DenoDoes PostGraphile work with Deno? Trying to see if I can run PostGraphile as a serverless function oIs there any way to disable Deno's Intellisense feature without disabling Deno itself?When programming with Deno, I've noticed how relatively slow the lang server is, and I need intellisDeploying Lume to github pagesI'm totaly new to this, but have been following instructions to build a site with lume. It works locBest hardware for Deno development?I am looking for a new laptop / desktop for Deno development as my current setup seems no longer viaHow do I make the crypto.subtle.digest algo flexible?This is a learning moment, bear with me. 😅 I can hard code an algo for the digest like this: ```t