denoland / deno_bindgen

Write high-level Deno FFI libraries in Rust.
MIT License
293 stars 27 forks source link

Segmentation fault with Deno Test #79

Open zifeo opened 2 years ago

zifeo commented 2 years ago

I felt on case looking close what is described upstream in https://github.com/rust-lang/rust/issues/88737. What debugging steps could be made in order to isolate further the issue (e.g. Deno and/or Rust and/or deeper)?

bartlomieju commented 2 years ago

Please provide a reproduction and output from your terminal, otherwise we're guessing in the blind.

zifeo commented 2 years ago

@bartlomieju That was painful to derive but here we go. Can you try on your end?

// src/lib.rs
use deno_bindgen::deno_bindgen;
use tokio::runtime::Runtime;

#[deno_bindgen]
fn ping() {}

#[deno_bindgen(non_blocking)]
fn start() {
    let rt = Runtime::new().unwrap();
    rt.block_on(F::new());
}

pub struct F {}

impl F {
    pub async fn new() {
        ()
    }
}
# Cargo.toml
[package]
name = "native"
version = "0.1.0"
edition = "2021"

[lib]
name = "native"
crate-type = ["cdylib"]

[dependencies]
deno_bindgen = "0.5.1"
tokio = { version = "1.19.2", features = ["full"] }
// a_test.ts
import * as native from "./bindings/bindings.ts";

Deno.test("a", async () => {
  await native.start();
})
// b_test.ts
import * as native from "./bindings/bindings.ts";

Deno.test("B", async () => {
    await native.ping();
})
# develop
cargo clean
deno_bindgen

deno test --unstable --allow-all a_test.ts 
> Check file:///home/zifeo/repro/a_test.ts
> running 1 test from ./a_test.ts
> a ... ok (6ms)
> 
> ok | 1 passed | 0 failed (55ms)

deno test --unstable --allow-all b_test.ts
> Check file:///home/zifeo/repro/b_test.ts
> running 1 test from ./b_test.ts
> B ... ok (4ms)
> 
> ok | 1 passed | 0 failed (41ms)

deno test --unstable --allow-all b_test.ts a_test.ts
> Check file:///home/zifeo/repro/b_test.ts
> Check file:///home/zifeo/repro/a_test.ts
> running 1 test from ./b_test.ts
> B ... ok (3ms)
> running 1 test from ./a_test.ts
> a ... ok (6ms)
> 
> ok | 2 passed | 0 failed (147ms)

deno test --unstable --allow-all a_test.ts b_test.ts 
> Check file:///home/zifeo/repro/a_test.ts
> Check file:///home/zifeo/repro/b_test.ts
> running 1 test from ./a_test.ts
> a ... ok (6ms)
> 'deno test --unstable --allow-...' terminated by signal SIGSEGV (Address boundary error)

# production
cargo clean
deno_bindgen --release

deno test --unstable --allow-all a_test.ts b_test.ts
> Check file:///home/zifeo/repro/a_test.ts
> Check file:///home/zifeo/repro/b_test.ts
> running 1 test from ./a_test.ts
> a ... ok (5ms)
> running 1 test from ./b_test.ts
> B ... ok (4ms)
> 
> ok | 2 passed | 0 failed (57ms)
bartlomieju commented 2 years ago

@littledivy can you take a look?

zifeo commented 2 years ago

@littledivy @bartlomieju Let me know if you need something else, this is definitely a blocker for the FFI.