D
Deno

help

Segfault when creating second rust MainWorker in program

Pprimoze11/16/2023
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.
DAHDeno AI Helper11/16/2023
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. 🦕
Pprimoze11/20/2023
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)
Mmarianoguerra11/20/2023
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.
Mmarvinh.11/21/2023
the runtime folks hang out more in #dev-core or #dev-rusty_v8 than here
Pprimoze11/23/2023
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
Mmarianoguerra11/23/2023
@primoze how do you initialize v8?
Pprimoze11/23/2023
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));
Pprimoze11/23/2023
this is just from the example at https://docs.rs/v8/latest/v8/
v8 - Rust
Example
Pprimoze11/23/2023
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

Looking for more? Join the community!

Recommended 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: ```twhat’s the current best practice for bundling?Is it deno esbuild? Wondering what supports npm specifiers and bundling atmHow do I get a d.ts file to be used?I'm extending a type from `hono` by adding that code in a `hono.d.ts` file in my `src` folder. ```“Log streaming API” on Deno DeployWhat does “Log streaming API” refers to in the analytics section of the pricing page of Deno Deploy?Read-only FS detectionHi, I have few deps that by default create cache/log dirs... I can disable it, but the detection itsIs there a built-in parser for the string that Deno.inspect produces?I found out in another thread that Deno.inspect(myObj) produces a visually gorgeous string representHow to get the nice Deno console.log format into a string?When I do a console.log on an instantiated class object, I get a beautiful format in the terminal, tbyonm - force use of DenoWhen I use byonm enabled in my deno.json, and say I have a vite project triggered from a package.jsoCan I disable deno linting for individual files, or a path?I'm using VSCode and the Deno extension. I want to use the inbuilt functionality of VSCode for type Rust run JS/TSHow can I embed this project into a rust application so that rust can run js ts and has runtime api Set-Cookie - Header shows as "deleted"I am trying to use deno to script/scrape a website. I can successfully log in to the site (using fet