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

Issue with monotonic clocks #103

Closed
sonhal opened this issue Apr 25, 2021 · 5 comments · Fixed by proxy-wasm/proxy-wasm-cpp-host#156
Closed

Issue with monotonic clocks #103

sonhal opened this issue Apr 25, 2021 · 5 comments · Fixed by proxy-wasm/proxy-wasm-cpp-host#156

Comments

@sonhal
Copy link

sonhal commented Apr 25, 2021

Hi, first thank you for this great project! I am having an issue with a filter targeting wasm32-wasi. When using code like:

std::time::Instant::now() or wasi::clock_time_get(CLOCKID_MONOTONIC, 1_000_000)

I get the following panic:

proxy_1 | [2021-04-25 19:52:37.278][8][critical][wasm] [source/extensions/common/wasm/context.cc:1180] wasm log: panicked at 'calledResult::unwrap()on anErrvalue: Error { code: 58, message: "Not supported, or operation not supported on socket." }', library/std/src/sys/wasi/time.rs:18:10

Seems like monotonic ClockId is not supported in Envoy host environment? Are you aware of this issue and do you know of any solution? I am aware that there is a proxy specific hostcall to get time, but I am depending on Json Web Token libraries that require monotonic clocks.

Example JWT library code for wasi target:

    #[cfg(target_os = "wasi")]
    fn _now() -> u64 {
        use wasi::{clock_time_get, CLOCKID_MONOTONIC};
        let nsec =
            unsafe { clock_time_get(CLOCKID_MONOTONIC, 1_000_000).expect("Clock not available") };
        _nsecs_to_u64(nsec)
    }
@mathetake
Copy link

currently only the realtime clock is supported on cpp-host implementation, but it's easy to implement. let me handle this.

@sonhal
Copy link
Author

sonhal commented Apr 26, 2021

Great! But does that mean I have to wait until the next Envoy release (or compile myself) to get the fix?

@PiotrSikora
Copy link
Member

Correct, there is no way to get monotonic clock right now.

@mathetake
Copy link

here it is: proxy-wasm/proxy-wasm-cpp-host#156

@jedisct1
Copy link

jedisct1 commented Apr 28, 2021

A temporary workaround for this was added to the coarsetime crate.

I'm going to tag a new version shortly, so that people can use code depending on it with the current version of Envoy.

Edit: Done.

jedisct1 added a commit to jedisct1/rust-coarsetime that referenced this issue Apr 28, 2021
lizan pushed a commit to envoyproxy/envoy that referenced this issue May 7, 2021
Supports clock_time_get in WASI with monotonic clock_id. Ref: proxy-wasm/proxy-wasm-cpp-host#156 and proxy-wasm/proxy-wasm-rust-sdk#103

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants