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

TinyGo Program blocks forever with os.Pipe, go proc, and a sleep; same program returns as expected with go #4237

Open
sparques opened this issue Apr 19, 2024 · 0 comments

Comments

@sparques
Copy link

Versions:

tinygo version 0.31.2 linux/amd64 (using go version go1.22.2 and LLVM version 17.0.1)

Code to replicate issue:

package main

import (
	"fmt"
	"io"
	"os"
	"time"
)

func main() {
	rd, wr, err := os.Pipe()
	if err != nil {
		panic(err)
	}
	defer wr.Close()
	defer rd.Close()

	go io.Copy(os.Stdout, rd)

	os.Stdout = wr

	fmt.Printf("testing\n")
	fmt.Printf("testing part 2")

	time.Sleep(2 * time.Second)
}

When ran with go (go run test.go), the two Printf statements show, then it exits as expected.

When ran with TinyGo (tinygo run test.go), it prints the statements then hangs forever. Checking with the debugger, it seems it's waiting for additional input from the go io.Copy(). Commenting out either the sleep or the go io.Copy() will let the program return normally.

This appears to be related to the use of os.Pipe(), because the same program written using io.Pipe() returns as expected.

Returns as expected:

package main

import (
	"fmt"
	"io"
	"os"
	"time"
)

func main() {
	rd, wr := io.Pipe()
	defer wr.Close()
	defer rd.Close()

	go io.Copy(os.Stdout, rd)

	fmt.Fprintf(wr, "testing\n")
	fmt.Fprintf(wr, "testing part 2")

	time.Sleep(2 * time.Second)
}
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

No branches or pull requests

1 participant