Add workaround for marine memory leak (#37)

This commit is contained in:
Valery Antopol 2022-06-28 18:17:28 +03:00 committed by GitHub
parent a329c8e062
commit 6f00f8282d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22646 additions and 335 deletions

View File

@ -18,9 +18,10 @@ jobs:
keys:
- aqua-ipfs00-{{ checksum "./service/pure/Cargo.lock" }}-{{ checksum "./service/effector/Cargo.lock" }}
- run: |
rustup toolchain install nightly-2021-04-24-x86_64-unknown-linux-gnu
rustup default nightly-2021-04-24-x86_64-unknown-linux-gnu
rustup target add wasm32-wasi --toolchain nightly-2021-04-24-x86_64-unknown-linux-gnu
rustup toolchain install nightly-2022-01-16-x86_64-unknown-linux-gnu
rustup default nightly-2022-01-16-x86_64-unknown-linux-gnu
rustup override set nightly-2022-01-16-x86_64-unknown-linux-gnu
rustup target add wasm32-wasi --toolchain nightly-2022-01-16-x86_64-unknown-linux-gnu
cd ./service
./build.sh
cargo test --no-fail-fast --release --all-features --

View File

@ -60,10 +60,10 @@ jobs:
- name: Install Rust
working-directory: ./service
run: |
rustup toolchain install nightly-2021-04-24-x86_64-unknown-linux-gnu
rustup default nightly-2021-04-24-x86_64-unknown-linux-gnu
rustup override set nightly-2021-04-24-x86_64-unknown-linux-gnu
rustup target add wasm32-wasi --toolchain nightly-2021-04-24-x86_64-unknown-linux-gnu
rustup toolchain install nightly-2022-01-16-x86_64-unknown-linux-gnu
rustup default nightly-2022-01-16-x86_64-unknown-linux-gnu
rustup override set nightly-2022-01-16-x86_64-unknown-linux-gnu
rustup target add wasm32-wasi --toolchain nightly-2022-01-16-x86_64-unknown-linux-gnu
### Build
- name: Build aqua-ipfs

15577
aqua/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
"*.aqua"
],
"dependencies": {
"@fluencelabs/aqua-lib": "^0.4.3"
"@fluencelabs/aqua-lib": "^0.5.2"
},
"scripts": {
"generate-aqua": "../service/build.sh",
@ -31,6 +31,6 @@
},
"homepage": "https://github.com/fluencelabs/aqua-ipfs#readme",
"devDependencies": {
"@fluencelabs/aqua": "0.7.1-291"
"@fluencelabs/aqua": "0.7.4-322"
}
}

7329
example/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,9 +14,9 @@
"license": "MIT",
"dependencies": {
"@fluencelabs/aqua-ipfs": "file:../aqua",
"@fluencelabs/aqua-lib": "0.4.3",
"@fluencelabs/aqua": "0.7.1-291",
"@fluencelabs/fluence": "^0.21.6",
"@fluencelabs/aqua-lib": "^0.5.2",
"@fluencelabs/aqua": "0.7.4-322",
"@fluencelabs/fluence": "^0.23.0",
"@fluencelabs/fluence-network-environment": "^1.0.13",
"ipfs-http-client": "^50.1.2",
"it-all": "^1.0.5",

View File

@ -19,8 +19,33 @@
#[cfg(target_arch = "wasm32")]
mod effector;
/*
_initialize function that calls __wasm_call_ctors is required to mitigade memory leak
that is described in https://github.com/WebAssembly/wasi-libc/issues/298
In short, without this code rust wraps every export function
with __wasm_call_ctors/__wasm_call_dtors calls. This causes memory leaks. When compiler sees
an explicit call to __wasm_call_ctors in _initialize function, it disables export wrapping.
TODO: remove when updating to marine-rs-sdk with fix
*/
#[cfg(target_arch = "wasm32")]
extern "C" {
pub fn __wasm_call_ctors();
}
#[cfg(target_arch = "wasm32")]
#[no_mangle]
fn _initialize() {
unsafe {
__wasm_call_ctors();
}
}
#[cfg(target_arch = "wasm32")]
pub fn main() {
_initialize(); // As __wasm_call_ctors still does necessary work, we call it at the start of the module
effector::main()
}

View File

@ -16,11 +16,36 @@
#![feature(try_blocks)]
/*
_initialize function that calls __wasm_call_ctors is required to mitigade memory leak
that is described in https://github.com/WebAssembly/wasi-libc/issues/298
In short, without this code rust wraps every export function
with __wasm_call_ctors/__wasm_call_dtors calls. This causes memory leaks. When compiler sees
an explicit call to __wasm_call_ctors in _initialize function, it disables export wrapping.
TODO: remove when updating to marine-rs-sdk with fix
*/
#[cfg(target_arch = "wasm32")]
extern "C" {
pub fn __wasm_call_ctors();
}
#[cfg(target_arch = "wasm32")]
#[no_mangle]
fn _initialize() {
unsafe {
__wasm_call_ctors();
}
}
#[cfg(target_arch = "wasm32")]
mod pure;
#[cfg(target_arch = "wasm32")]
pub fn main() {
_initialize(); // As __wasm_call_ctors still does necessary work, we call it at the start of the module
pure::main()
}