Stream: git-wasmtime

Topic: wasmtime / issue #9174 Native Golang build + file access ...


view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2024 at 18:35):

brendandburns added the bug label to Issue #9174.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2024 at 18:35):

brendandburns opened issue #9174:

Test Case

package main

import (
    "fmt"
    "log"
    "os"
)

func main() {
    stat, err := os.Stat("./")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%s\n", stat.Name())

    entries, err := os.ReadDir("./")
    if err != nil {
        log.Fatal(err)
    }
    for _, entry := range entries {
        fmt.Printf("\t%s\n", entry.Name())
    }

    file, err := os.Open("main.go")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%s\n", file.Name())

    if err := os.WriteFile("test.txt", []byte("This is test data"), 0x777); err != nil {
        log.Fatal(err)
    }
}

Steps to Reproduce

Expected Results

Generated code should be able to open files mapped in via --dir

Actual Results

``
...
2024/08/27 18:27:51 open main.go: Bad file number

### Versions and Environment

Wasmtime version or commit: 24.0

Operating system: Linux

Architecture: x86_64

### Extra Info

I don't know if this is a Golang or a wasmtime issue.
~~~

view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2024 at 18:35):

brendandburns edited issue #9174:

Test Case

package main

import (
    "fmt"
    "log"
    "os"
)

func main() {
    stat, err := os.Stat("./")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%s\n", stat.Name())

    entries, err := os.ReadDir("./")
    if err != nil {
        log.Fatal(err)
    }
    for _, entry := range entries {
        fmt.Printf("\t%s\n", entry.Name())
    }

    file, err := os.Open("main.go")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%s\n", file.Name())

    if err := os.WriteFile("test.txt", []byte("This is test data"), 0x777); err != nil {
        log.Fatal(err)
    }
}

Steps to Reproduce

Expected Results

Generated code should be able to open files mapped in via --dir

Actual Results

...
2024/08/27 18:27:51 open main.go: Bad file number

Versions and Environment

Wasmtime version or commit: 24.0

Operating system: Linux

Architecture: x86_64

Extra Info

I don't know if this is a Golang or a wasmtime issue.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2024 at 19:06):

bjorn3 commented on issue #9174:

Can you try running with WASMTIME_LOG=wasmtime_wasi=trace? That should show all wasi syscalls executed by the wasm module with all arguments and error results.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 28 2024 at 16:23):

primoly commented on issue #9174:

The issue does not occur if you use wasmtime --dir .::/ main.wasm (Note the .::/ instead of .::.)

I think Go always adds a / at the beginning of the path. Changing to os.Open("./main.go") does not resolve the issue.

Rust’s std::fs::File::open works with both absolute and relative paths as it uses wasi-libc which does the mapping automatically so I guess this is an issue with the Go bindings to Wasi.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 28 2024 at 18:13):

brendandburns closed issue #9174:

Test Case

package main

import (
    "fmt"
    "log"
    "os"
)

func main() {
    stat, err := os.Stat("./")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%s\n", stat.Name())

    entries, err := os.ReadDir("./")
    if err != nil {
        log.Fatal(err)
    }
    for _, entry := range entries {
        fmt.Printf("\t%s\n", entry.Name())
    }

    file, err := os.Open("main.go")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%s\n", file.Name())

    if err := os.WriteFile("test.txt", []byte("This is test data"), 0x777); err != nil {
        log.Fatal(err)
    }
}

Steps to Reproduce

Expected Results

Generated code should be able to open files mapped in via --dir

Actual Results

...
2024/08/27 18:27:51 open main.go: Bad file number

Versions and Environment

Wasmtime version or commit: 24.0

Operating system: Linux

Architecture: x86_64

Extra Info

I don't know if this is a Golang or a wasmtime issue.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 28 2024 at 18:13):

brendandburns commented on issue #9174:

Changing --dir .::.. to --dir .::/ fixes things.

I agree that this feels like a bug in the Go + Wasi bindings, I'll look into that codebase.

Closing this issue here.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 28 2024 at 18:13):

brendandburns edited a comment on issue #9174:

Changing --dir .::. to --dir .::/ fixes things.

I agree that this feels like a bug in the Go + Wasi bindings, I'll look into that codebase.

Closing this issue here.


Last updated: Dec 23 2024 at 12:05 UTC