-
Notifications
You must be signed in to change notification settings - Fork 2.6k
wasm trap: out of bounds memory access #10095
Comments
Maybe related: Phala-Network/phala-blockchain#542 |
@AurevoirXavier how can we reproduce this? |
I'm not sure what causes this. I can't give a minimal env to reproduce this.
At the end of the session, this error will pop up. And the chain get stalled. |
Found the problem. Our WASM instance fast reuse code is not clearing Here's what exactly happens:
A workaround for this issue would be to either switch to an interpreted WASM runtime @bkchr I know that the fast reuse codepath deliberately retains some things between calls (e.g. the linear memory itself); not sure if this behavior is intended, but if it is then in my opinion this is way too dangerous to leave unfixed. |
Okay. That doesn't sound good. Fast instance reuse should explicitly reset static variables. Cc @pepyakin |
This should test it |
or the |
Interesting; I'll check why the tests don't fail here. |
FWIW, filled an issue that I meant to fill for some time #10244 TL;DR: Since wasmtime evolved quite some, we may not need to use |
Okay, it looks like the To get WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.build() and the pub fn import_memory(mut self) -> Self {
self.rust_flags.push("-C link-arg=--import-memory".into());
self
}
// ...
build_cmd.args(&["rustc", "--target=wasm32-unknown-unknown"])
// ...
.env("RUSTFLAGS", rustflags.clone()) But it doesn't work. Why? We're calling the The good news is that Basti has already inadvertently fixed the issue with the // exclusive). The runner project is created in `CARGO_TARGET_DIR` and executing it will
// create a sub target directory inside of `CARGO_TARGET_DIR`.
.env_remove("CARGO_TARGET_DIR")
+ // As we are being called inside a build-script, this env variable is set. However, we set
+ // our own `RUSTFLAGS` and thus, we need to remove this. Otherwise cargo favors this
+ // env variable.
+ .env_remove("CARGO_ENCODED_RUSTFLAGS")
// We don't want to call ourselves recursively
.env(crate::SKIP_BUILD_ENV, ""); So with that PR merged the runtime is once again built with the necessary flag and is compatible with our current fast instance reuse code. (@AurevoirXavier @h4x3rotab FYI you'll probably want to at least backport this patch into your codebases and rebuild your runtimes.) Anyway, since using the fast instance reuse codepath on any runtime built without the |
Now as you say this :D I have done this change there not inadvertently. If I remember correctly, the fast instance reuse test failed and I have fixed it...
Sounds good to me. We should also make |
@koute Any other way to pass the |
@AurevoirXavier you need this patch: 73acb2a |
You don't have to upgrade the whole [edit]Ninja'd by Basti (:[/edit] |
Aha, yes! I have just thought about that. Thanks! |
Just a PSA - I said that disabling fast instance reuse is one possible workaround for this too; do not disable it. There's a bug in |
10k instances? That sounds as if the pooling strategy (#10244) was already enabled... At least I vaguely remember this limit from there. Likely I am wrong |
It's because we use the same
So this not only results in a memory leak, but also essentially breaks the executor after 10k invocations. I'm currently in the process of fixing that, and after that we can turn on the pooling (which requires us to actually drop the |
Happened on
linux-gnu-nightly-2021-09-01
. Downgrade tolinux-gnu-nightly-2021-04-22
got fixed.But still happened on
windows-msvc-nightly-2021-04-22
, and got fixed by upgrading towindows-msvc-nightly-2021-05-01
.I'm not sure if this is a rust issue or parity wasm issue.
Other projects also encounter this. cc @h4x3rotab
darwinia-network/darwinia-common#879
Phala-Network/phala-blockchain#542
The text was updated successfully, but these errors were encountered: