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

1.78.0 & WASM - panicked at dlmalloc.rs: assertion failed: psize <= size + max_overhead #124671

Closed
lucasavila00 opened this issue May 3, 2024 · 5 comments
Labels
C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@lucasavila00
Copy link

I'm having a hard time minifying this. But the error happens consistently.

This error happens on my open source repository: lucasavila00/beff#186

The error doesn't happen on rust 1.77.2 but it does on 1.78.

Meta

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2
Backtrace

examples/bug-rust-repro beff$ beff -p beff.json
│ panicked at /rust/deps/dlmalloc-0.2.6/src/dlmalloc.rs:1198:13:
│ assertion failed: psize <= size + max_overhead
│ Stack:
│ Error
│     at /home/lucas/fluff/beff/packages/beff-cli/pkg/beff_wasm.js:534:17
│     at logError (/home/lucas/fluff/beff/packages/beff-cli/pkg/beff_wasm.js:218:18)
│     at module.exports.__wbg_new_abda76e883ba8a5f (/home/lucas/fluff/beff/packages/beff-cli/pkg/beff_wasm.js:533:65)
│     at beff_wasm.wasm.console_error_panic_hook::Error::new::h3fb258f8a950d48b (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[19976]:0x8d831d)
│     at beff_wasm.wasm.console_error_panic_hook::hook_impl::h408f3114d4740dae (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[4051]:0x66ed1e)
│     at beff_wasm.wasm.console_error_panic_hook::hook::hf663b256d6060a70 (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[21327]:0x8eb593)
│     at beff_wasm.wasm.core::ops::function::Fn::call::ha3ef796f8ab2de10 (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[18478]:0x8c1286)
│     at beff_wasm.wasm.std::panicking::rust_panic_with_hook::h32c80a64fe4de396 (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[7483]:0x763905)
│     at beff_wasm.wasm.std::panicking::begin_panic_handler::{{closure}}::hd496964d114e98b9 (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[10505]:0x7f060e)
│     at beff_wasm.wasm.std::sys_common::backtrace::__rust_end_short_backtrace::h0d4686a7fe3981a4 (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[24266]:0x906f66)
│ wasm://wasm/beff_wasm.wasm-02dffe6e:1
│ RuntimeError: unreachable
│     at beff_wasm.wasm.__rust_start_panic (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[24291]:0x906ff5)
│     at beff_wasm.wasm.rust_panic (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[24015]:0x90640c)
│     at beff_wasm.wasm.std::panicking::rust_panic_with_hook::h32c80a64fe4de396 (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[7483]:0x763932)
│     at beff_wasm.wasm.std::panicking::begin_panic_handler::{{closure}}::hd496964d114e98b9 (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[10505]:0x7f060e)
│     at beff_wasm.wasm.std::sys_common::backtrace::__rust_end_short_backtrace::h0d4686a7fe3981a4 (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[24266]:0x906f66)
│     at beff_wasm.wasm.rust_begin_unwind (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[20490]:0x8dfe55)
│     at beff_wasm.wasm.core::panicking::panic_fmt::hc7427f902a13f1a9 (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[21224]:0x8ea070)
│     at beff_wasm.wasm.core::panicking::panic::hb157b525de3fe68d (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[19225]:0x8ccfe4)
│     at beff_wasm.wasm.__rdl_dealloc (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[15145]:0x880db6)
│     at beff_wasm.wasm.__rust_dealloc (wasm://wasm/beff_wasm.wasm-02dffe6e:wasm-function[23972]:0x906180)
│ Node.js v18.18.0

You can reproduce it by cloning the repository, installing dependencies with pnpm i and run compile and tests with DEBUG=true pnpm all

It only happens if the tool is used to parse typescript source code containing the character , like the following

And it only happens if compiled to wasm. x86 with cargo test works as expected.

import parse from "./generated/parser";

// ‘

type A = string;
export const { A } = parse.buildParsers<{
  A: A;
}>();

I added some debug logs, and the code fails to return from get_or_fetch_file

$ npm run beff -- -v

> standalone-parser@1.0.36 beff
> beff -p beff.json -v

JS: Parser entry point /home/lucas/fluff/beff/examples/bug-rust-repro/src/parser.ts
RUST: Start extract parser...
RUST: Start visit_current_file...
RUST: start get_current_file...
RUST: get_or_fetch_file...
RUST: Parsing file BffFileName("/home/lucas/fluff/beff/examples/bug-rust-repro/src/parser.ts")
RUST: Visiting file BffFileName("/home/lucas/fluff/beff/examples/bug-rust-repro/src/parser.ts")
JS: Resolved -import ? from './generated/parser'- at /home/lucas/fluff/beff/examples/bug-rust-repro/src/parser.ts => undefined
RUST: Finished parse & visit file BffFileName("/home/lucas/fluff/beff/examples/bug-rust-repro/src/parser.ts")
RUST: get_or_fetch_file inserted...
RUST: get_or_fetch_file built s...
panicked at /rust/deps/dlmalloc-0.2.6/src/dlmalloc.rs:1198:13:

untitled(31)

I'm trying to minify this further, but it's tricky. I'll update this issue if I can minify it further.

I'm creating the issue because maybe someone else has this issue and it helps to narrow it down. I searched around and I could not find related issues.

@lucasavila00 lucasavila00 added the C-bug Category: This is a bug. label May 3, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 3, 2024
@lucasavila00 lucasavila00 changed the title WASM - panicked at dlmalloc.rs: assertion failed: psize <= size + max_overhead 1.78.0 & WASM - panicked at dlmalloc.rs: assertion failed: psize <= size + max_overhead May 3, 2024
@workingjubilee workingjubilee added the O-wasm Target: WASM (WebAssembly), http://webassembly.org/ label May 3, 2024
@workingjubilee
Copy link
Member

It looks like it hits the assertion in here:

https://github.com/alexcrichton/dlmalloc-rs/blob/4bf7569d1127a12fe902b1e707127afb98bec717/src/dlmalloc.rs#L1187-L1200

This might be a library issue. It is common for a dependency like dlmalloc to be conditionally used on some targets.

@Noratrieb Noratrieb added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 3, 2024
@Noratrieb
Copy link
Member

dlmalloc-rs is a dep of std for the default global allocator. but probably also worth opening an issue upstream

@workingjubilee
Copy link
Member

Oh neat! Good to know.

@lucasavila00
Copy link
Author

This is intentional behavior. See alexcrichton/dlmalloc-rs#32

I'm sorry for the noise

@lucasavila00
Copy link
Author

For anyone searching this:

Upgrading wasm_bindgen fixed it for me.

Likely related to rustwasm/wasm-bindgen#3801 and rustwasm/wasm-bindgen#3808

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants