Skip to content

Commit

Permalink
Add memory leak temporary mitigation (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeryAntopol authored Jun 28, 2022
1 parent b9fbbbc commit aa72fda
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import {trusted_computation} from "./generated/computation";
import { trusted_computation } from "./generated/computation";
import * as tg from "./generated/export";
import {Fluence, FluencePeer, KeyPair} from "@fluencelabs/fluence";
import {krasnodar, Node, testNet, stage} from "@fluencelabs/fluence-network-environment";
import { Fluence, FluencePeer, KeyPair } from "@fluencelabs/fluence";
import { krasnodar, Node, testNet, stage } from "@fluencelabs/fluence-network-environment";
import assert from "assert";
const bs58 = require('bs58');

Expand Down Expand Up @@ -92,7 +92,7 @@ async function main() {
let builtins_keypair = await KeyPair.fromEd25519SK(sk);

let relay = local[0];
await Fluence.start({ connectTo: relay, KeyPair: builtins_keypair});
await Fluence.start({ connectTo: relay, KeyPair: builtins_keypair });
console.log(
"📗 created a fluence peer %s with relay %s",
Fluence.getStatus().peerId,
Expand Down
2 changes: 1 addition & 1 deletion service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trust-graph-wasm"
version = "0.3.0"
version = "0.3.1"
authors = ["Fluence Labs"]
edition = "2018"
description = "trust graph wasm"
Expand Down
21 changes: 21 additions & 0 deletions service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,31 @@ mod results;
mod service_api;
mod storage_impl;
mod tests;
/*
_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
*/
extern "C" {
pub fn __wasm_call_ctors();
}

#[no_mangle]
fn _initialize() {
unsafe {
__wasm_call_ctors();
}
}
//------------------------------
pub static TRUSTED_TIMESTAMP: (&str, &str) = ("peer", "timestamp_sec");

pub fn main() {
_initialize(); // As __wasm_call_ctors still does necessary work, we call it at the start of the module
WasmLoggerBuilder::new()
.with_log_level(log::LevelFilter::Trace)
.build()
Expand Down

0 comments on commit aa72fda

Please sign in to comment.