-
Notifications
You must be signed in to change notification settings - Fork 18k
archive/tar: io.copy hangs when using io.pipe and tarReader #53110
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
Comments
This sounds good to me. // reading tarReader bytes using a io.pipe from file
func doesNotWork() error {
pr, pw := io.Pipe()
errC := make(chan error, 1)
go func() {
- defer func() { _ = pw.Close() }()
errC <- readTar(DummyTar, pw)
}()
tarR := tar.NewReader(pr)
bArray := make([]byte, 1)
for {
_, err := tarR.Read(bArray)
if err == io.EOF {
fmt.Println("EOF reached!")
break
} else if err != nil {
return err
}
}
+ pw.Close()
<-errC
fmt.Println("doesNotWork finished successfully")
return nil
} This works. As far I can tell, reading the file from Could also be that some padding data is left in the underlying reader and that |
@Jorropo Thanks for your help with this! You're right, I found 512 bytes in the pipe reader that needed to be drained after the tar It is still is a little odd to me that |
This is an incorrect use of Closing as not a bug |
For anyone that may come across this issue. I still see this issue rarely with some tar files (will try to upload an example) while explicitly using |
What version of Go are you using (
go version
)?go version go1.18.2 darwin/arm64
go version go1.17.6 darwin/arm64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
In this little example I show 3 cases:
https://go.dev/play/p/cDqxssuAaT2
What did you expect to see?
The io.pipe to close after fully reading the file to EOF when using tarReader and io.pipe.
What did you see instead?
The io.copy hangs indefinitely after the EOF is reached and the pipe is empty.
The text was updated successfully, but these errors were encountered: