wasmerio / wasmer

🚀 The leading Wasm Runtime supporting WASIX and WASI
https://wasmer.io
MIT License
18.93k stars 811 forks source link

clock_nanosleep doesn't work as expected #4249

Open daichifukui opened 1 year ago

daichifukui commented 1 year ago

Describe the bug

clock_nanosleep with TIMER_ABSTIME does not return if it is called in a thread different from the main thread, using wasmer.

Conditions are:

The details of wasmer:

$ wasmer -vV
wasmer 4.1.1 (0bd4b48 2023-08-03)
binary: wasmer-cli
commit-hash: 0bd4b48691924127200ea206f72b813e85d11520
commit-date: 2023-08-03
host: x86_64-unknown-linux-gnu
compiler: singlepass,cranelift,llvm

Steps to reproduce

# view source code
$ cat clock_nanosleep_abs.c
#include <time.h>
#include <stdio.h>

int main(void)
{
        int ret;
        struct timespec ts;
        clock_gettime(CLOCK_MONOTONIC,&ts);
        ts.tv_sec += 1;
        ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL);
        if (ret)
                perror("clock_nanosleep");
        return 0;
}

# compile
$  /home/user/wasi-sdk-20.0/bin/clang \
--sysroot=/home/user/wasi-libc/sysroot \
-Wall \
-Wno-nonnull \
-Wextra \
-O2 \
-Wl,--max-memory=4294967296 \
-Wl,--export-dynamic \
clock_nanosleep_abs.c \
-o cn_abs

# run
$  /home/user/.wasmer/bin/wasmer run --enable-all ./cn_abs

# the program should return in 1 second but it doesn't actually

Expected behavior

clock_nanosleep returns when the requested time expires

Actual behavior

clock_nanosleep does not return even after the requested time expires

Additional context

In addition to wasmer, I've tried wasmtime, wasmedge, and iwasm and followed the same steps to reproduce shown above.
The result shows that clock_nanosleep lets the program sleep for expected duration with all of the three runtimes.
In short, clock_nanosleep works fine with the runtimes except for wasmer.

FYI, the version of each runtime is as follows:

daichifukui commented 1 year ago

At first I suspected this was an issue with wasi-libc, but we found this is more related to wasmer as disscussed in https://github.com/WebAssembly/wasi-libc/issues/439, hence this issue.

stale[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.