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

os: Stdin.Stat().Size() always returns 0 with GOOS=wasip1 GOARCH=wasm #62392

Closed
williamwebb opened this issue Aug 31, 2023 · 3 comments
Closed
Labels
arch-wasm WebAssembly issues NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@williamwebb
Copy link

What version of Go are you using (go version)?

go1.21.0 darwin/arm64

Does this issue reproduce with the latest release?

Yes, but only tested against GOOS=wasp1 GOARCH=wasm

What operating system and processor architecture are you using (go env)?

go env Output
GOOS=wasp1 GOARCH=wasm

What did you do?

read Stdin, check stat.size

stdin := os.Stdin
stat, _ := stdin.Stat()
fmt.Println("size:", stat.Size())             

run via wasi runtime, piping input to stdin

echo "input" | wasmer run wasi_binary

What did you expect to see?

size should match contents of stdin

What did you see instead?

size of 0 is always returned

@dmitshur dmitshur changed the title affected/package: os.Stdin.Stat().Size() always returns 0 with GOOS=wasp1 GOARCH=wasm os: Stdin.Stat().Size() always returns 0 with GOOS=wasip1 GOARCH=wasm Aug 31, 2023
@dmitshur
Copy link
Contributor

CC @golang/wasm.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 31, 2023
@dmitshur dmitshur added this to the Backlog milestone Aug 31, 2023
@achille-roussel
Copy link
Contributor

Hello @williamwebb, thanks for reporting the issue.

I believe that the behavior you expect is not something that Go can satisfy; the webassembly runtime is in charge of implementing host system calls such as the one involved in getting the size of an open file, the Go standard library (and in particular the os package in this case) only expose what the runtime returns.

in your example, it appears that wasmer returns a zero size for the standard input stream; this behavior will be the same regardless of the original programming language from which the webassembly module was compiled.

That being said, I was curious to explore how other platforms may behave, so I tested your code snippet:

  • on darwin/arm64
$ echo input | go run main.go
size: 6
  • on linux/amd64
$ echo input | go run main.go
size: 0

As you can see, programs that rely on the behavior of asking the size of stdin will not be portable across platforms; combinations of operating systems and webassembly runtimes will produce different results.

@dmitshur I believe we can close this issue since Go behaves as expected in this case.

@dmitshur
Copy link
Contributor

dmitshur commented Sep 1, 2023

Thanks for investigating this report.

@dmitshur dmitshur closed this as not planned Won't fix, can't repro, duplicate, stale Sep 1, 2023
@dmitshur dmitshur added the arch-wasm WebAssembly issues label Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly issues NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants