Skip to content

Issue with monotonic clocks #103

Closed
proxy-wasm/proxy-wasm-cpp-host
#156
@sonhal

Description

@sonhal

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)
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions