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

[Bug]: Resource restrictions for WASM code execution in SmartStream #1245

Open
avinassh opened this issue Jul 15, 2021 · 2 comments
Open

[Bug]: Resource restrictions for WASM code execution in SmartStream #1245

avinassh opened this issue Jul 15, 2021 · 2 comments
Labels
bug Something isn't working no-stale Opt-out of closing issue due to no activity

Comments

@avinassh
Copy link
Contributor

I was checking what all resource restrictions have been set for WASM code execution. All the tests have been done locally with the latest master 2c0005d

I created a smart stream filter which never really exits:

#[smartstream(filter)]
pub fn filter(record: &Record) -> bool {
    let str_result = std::str::from_utf8(record.value.as_ref());
    let string = match str_result {
        Ok(s) => s,
        _ => return false,
    };
    let mut c = 0;
    loop {
        c += 1;
    }
    eprintln!("{}", c);
    string.contains('a')
}

I ran the consumer on my terminal which just hung till I cancelled. The CPU usage shot to 70% (from 30%). I kept it running for few minutes, assuming if there were any max time set on these operations. Then I manually cancelled.

Also tried code with infinite recursion, this also behaves like previous code and CPU usage increased:

   // omitted for brevity

    // never ending recursion
    fn fact(x: u32) -> u32 { if x == 0 {1} else {fact(x)} }
    eprintln!("{:?}", fact(5));
    string.contains('a')
}

From our discussion from Discord, @sehz suggested setting consume_fuel to solve these issues.


Reporting for the sake of completeness, I am mentioning other things I tried. In the following, WASM engine gave error and consumer returned immediately:

  1. code with sleep statement
  2. code with process.exit

I wanted to test for memory limits, but could not come up with rust code which grew in memory. Related issues in wastime (#1872, #2273)

my code:

#[smartstream(filter)]
pub fn filter(record: &Record) -> bool {
    let str_result = std::str::from_utf8(record.value.as_ref());
    let string = match str_result {
        Ok(s) => s,
        _ => return false,
    };
    let mut my_vector = Vec::new();
    let random_string = String::from("abcdefghijklmnopqrstuvwxyz");
    loop {
        my_vector.push(random_string.clone());
    }
    my_vector.last().unwrap().contains('a')
}

But this was handled properly by the SPU with the following error:

Jul 15 19:49:00.148 ERROR stream fetch{starting_offset=0 replica=echo-0 sink=15}: fluvio_spu::services::public::stream_fetch: error: IoError(
    Custom {
        kind: Other,
        error: "filter err wasm trap: unreachable\nwasm backtrace:\n    0: 0x67a1 - <unknown>!alloc::raw_vec::RawVec<T,A>::reserve::do_reserve_and_handle::h7d6e15d165e7e76e\n    1: 0x9a1a - <unknown>!filter\nnote: run with `WASMTIME_BACKTRACE_DETAILS=1` environment variable to display more information\n",
    },
)
@github-actions
Copy link

Stale issue message

@github-actions
Copy link

Stale issue message

@tjtelan tjtelan added no-stale Opt-out of closing issue due to no activity and removed no-issue-activity labels Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working no-stale Opt-out of closing issue due to no activity
Projects
None yet
Development

No branches or pull requests

4 participants