go: net: io.CopyN fails to copy from file to net.Conn on Windows
What version of Go are you using (go version)?
go version go1.10.2 windows/amd64
Does this issue reproduce with the latest release?
That is the latest (stable) release.
What operating system and processor architecture are you using (go env)?
windows/amd64
What did you do?
- Be on Windows (I tried this on Linux and couldn’t reproduce the bug.)
- Build this program:
package main
import (
"fmt"
"io"
"net"
"os"
"time"
)
func main() {
l, err := net.Listen("tcp", ":1234")
fmt.Println(err)
for {
conn, err := l.Accept()
fmt.Println(err)
f, err := os.Open("alphabet.txt")
fmt.Println(err)
for {
n, err := io.CopyN(conn, f, 3)
fmt.Println(n, err)
if err != nil {
break
}
time.Sleep(1 * time.Second)
}
conn.Close()
}
}
- Create a file
alphabet.txt:
abcdefghijklmnopqrstuvwxyz
- Run the program
- Connect to port 1234 with PuTTY or netcat.
What did you expect to see?
abc <pause> def <pause> ghi <pause> jkl ...
What did you see instead?
abc <pause> def <pause> def <pause> def ...
Notes
I could only reproduce this when copying from a file to a network connection. If I for example replace the network connection with os.Stdout or the file with strings.NewReader() the issue doesn’t happen.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 40 (23 by maintainers)
Commits related to this issue
- net: add TestSendfileParts Add test for freebsd issue #25809. This test also fails on my Windows 10 Version 1803. My hope is that adding new test will break one of our builders. Updates #25722 Upda... — committed to golang/go by alexbrainman 6 years ago
- internal/poll: advance file position in windows sendfile Some versions of Windows (Windows 10 1803) do not set file position after TransmitFile completes. So just use Seek to set file position before... — committed to fancybits/go by alexbrainman 6 years ago
- net: add TestSendfileParts Add test for freebsd issue #25809. This test also fails on my Windows 10 Version 1803. My hope is that adding new test will break one of our builders. Updates #25722 Upda... — committed to fancybits/go by alexbrainman 6 years ago
- internal/poll: specify current file position when calling TransmitFile Current SendFile implementation assumes that TransmitFile starts from the current file position. But that appears not true for W... — committed to fancybits/go by alexbrainman 6 years ago
- internal/poll: advance file position in windows sendfile Some versions of Windows (Windows 10 1803) do not set file position after TransmitFile completes. So just use Seek to set file position before... — committed to fancybits/go by alexbrainman 6 years ago
- internal/poll: advance file position in windows sendfile Some versions of Windows (Windows 10 1803) do not set file position after TransmitFile completes. So just use Seek to set file position before... — committed to fancybits/go by alexbrainman 6 years ago
- [release-branch.go1.10] internal/poll: specify current file position when calling TransmitFile Current SendFile implementation assumes that TransmitFile starts from the current file position. But tha... — committed to golang/go by alexbrainman 6 years ago
- [release-branch.go1.10] internal/poll: advance file position in windows sendfile Some versions of Windows (Windows 10 1803) do not set file position after TransmitFile completes. So just use Seek to ... — committed to golang/go by alexbrainman 6 years ago
I also got fail on Windows 10 64bit.
@alexbrainman I think your change doesn’t trigger the bug. At least the part about advancing file position. Simple test would be to call
CopyN(conn, f, 3)three times in a row and compare the result on the other end with "Produced ". You don’t want to seek. This bug will cause the string to be “Producduc” instead.