-
Notifications
You must be signed in to change notification settings - Fork 40
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
Rust 1.78 introduced a panic in our application #41
Comments
cc @SFBdragon and #37, would you be able to help investigate this? |
Also, @elpiel, could you detail how to reproduce this with the repository you linked? |
|
Although it might not be related, I think it's good to link these issues and repos as well. They mention a nightly bug: |
I'm willing to investigate but I can't say for sure when I'll be able to. Hopefully within a few days. At this point I'm very tempted to write a "safe" memory allocator to help comprehensively detect allocation issues at runtime, given the (relatively small, I imagine!) number of allocation bugs I've diagnosed in the Rust WASM ecosystem from bug reports. In the meantime, I'm curious what happens if you substitute |
We are also seeing this behaviour internally; our WASM modules are dying at random, likely after some allocation of a few dozen kilobytes. I'll try to collect more data and report back. The initial issue we commented upon was rustwasm/wasm-pack#1389, but I suspect that this is the root cause issue? |
@philpax Thanks for letting us know. Given this seems to be effecting quite a few people, I'll try to make time to dive into this today, then 👍 |
I wrote a quick test WASM application to determine if it was a fragmentation issue, but I can't reproduce the issue on 1.78.0: [package]
name = "dlmalloc_test"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2" use wasm_bindgen::prelude::*;
static mut LAST_BYTES: Vec<Vec<u8>> = Vec::new();
#[wasm_bindgen]
pub fn allocate(bytes: usize) -> usize {
unsafe {
if LAST_BYTES.len() > 10 {
LAST_BYTES.remove(0);
}
LAST_BYTES.push(vec![0; bytes]);
LAST_BYTES.iter().map(|b| b.len()).sum()
}
} <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>dlmalloc test</title>
<script type="module">
import init, { allocate } from "./pkg/dlmalloc_test.js";
async function run() {
await init();
setInterval(() => {
let bytesNow = Math.floor(Math.random() * 1000000);
let bytesActive = allocate(bytesNow);
let output = document.getElementById("output");
let msg = `Total: ${bytesActive}b | Now: ${bytesNow}b`;
output.textContent = msg;
console.log(msg);
}, 20);
}
run();
</script>
</head>
<body>
<p id="output"></p>
</body>
</html> This runs indefinitely without crashing. I was hoping this would catch it so that I could alter the asserts to print the values, but it looks like it'll take a bit more work to reproduce! This is definitely using dlmalloc and has the assert available:
|
Update: I don't think this is an issue with Error and stack trace
I suspect we just have a bad deallocation on our hands; this wouldn't be the first time rustwasm/wasm-bindgen#3801 The reason for this is that I'll poke around a bit more to try narrow down the cause. (I suspect |
Inspired by #41 but hasn't actually found any issues.
Thanks for taking a look at this @SFBdragon! Your conclusion, a buggy alloc/dealloc in |
Update 2:For others also hunting down the bug, we are indeed looking for a badly sized deallocation. I logged all the allocations/deallocations/reallocations:
That size is very consistent. (Note that this likely isn't the same exact allocation |
Thank you very much for spend time on this bug! I will follow up on the other issue in wasm-pack then. |
For anyone landing on this issue, it seems that in the latest revision on
https://github.com/rustwasm/wasm-bindgen/blob/0.2.92/CHANGELOG.md#fixed-1 OR
https://github.com/rustwasm/wasm-bindgen/blob/0.2.92/CHANGELOG.md#0287 |
The default allocator (dlmalloc-rs) caused panic in workspaces with very large number of files and bumping wasm-bindgen to latest didn't help. See the issue: alexcrichton/dlmalloc-rs#41
First of all, thank you very much for working on this allocator (it seems that it's still the only one feature-rich enough for wasm in Rust)!
After a recent upgrade to Rust 1.78 our application started getting a panic message:
I've tried re-compiling the wasm module on 1.76 and 1.77 and did not get the panic message.
I believe this could be related to recent changes in the Rust compiler which are causing this misbehavior:
https://blog.rust-lang.org/2024/05/02/Rust-1.78.0.html#asserting-unsafe-preconditions
https://blog.rust-lang.org/2024/05/02/Rust-1.78.0.html#deterministic-realignment
Honestly, I don't feel competent enough to dig into the
dlmalloc
code and debug our wasm module but I'll be happy to get some guidance or help with debugging this issue.PS: Our application is open-source and the wasm build can be found here: https://github.com/Stremio/stremio-core-web
The text was updated successfully, but these errors were encountered: