Skip to content

os: io.Copy(net.Conn, os.Stdin) on MacOS terminate immediately without waiting for input #70763

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

Closed
tienqdo opened this issue Dec 11, 2024 · 17 comments
Labels
Critical A critical problem that affects the availability or correctness of production systems built using Go FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done. OS-Darwin release-blocker
Milestone

Comments

@tienqdo
Copy link

tienqdo commented Dec 11, 2024

Go version

go version go1.23.3 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/tien/Library/Caches/go-build'
GOENV='/Users/tien/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/tien/.asdf/installs/golang/1.23.3/packages/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/tien/.asdf/installs/golang/1.23.3/packages'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/tien/.asdf/installs/golang/1.23.3/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/tien/.asdf/installs/golang/1.23.3/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.23.3'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/tien/Library/Application Support/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/tien/code/learning/the-go-programming-language/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/fw/flzm6v7d6dn9n3255s6c69v00000gn/T/go-build4294646491=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Running a server: https://go.dev/play/p/5I1sJlo64VB
And a client: https://go.dev/play/p/fOMykC2RbYs

What did you see happen?

The client exits immediately without waiting for the input

What did you expect to see?

The client wait for the input

@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@seankhliao
Copy link
Member

consider checking the error on the copy operation

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 11, 2024
@tienqdo
Copy link
Author

tienqdo commented Dec 11, 2024

@seankhliao there is no error, io.Copy returns 0, nil.

I ran the same code on a linux machine, and it worked as expected, so this only happens on MacOS.

@seankhliao
Copy link
Member

and how are you running this?

@tienqdo
Copy link
Author

tienqdo commented Dec 11, 2024

@seankhliao I'm using go run to run the server & the client files separately

@ianlancetaylor ianlancetaylor changed the title import/path: io.Copy(net.Conn, os.Stdin) on MacOS terminate immediately without waiting for input os: io.Copy(net.Conn, os.Stdin) on MacOS terminate immediately without waiting for input Dec 11, 2024
@ianlancetaylor ianlancetaylor added OS-Darwin NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Dec 11, 2024
@ianlancetaylor
Copy link
Contributor

I tried it on a Darwin system using Go tip and io.Copy returned an error:

readfrom tcp [::1]:51606->[::1]:8000: sendfile: operation not supported

@ianlancetaylor
Copy link
Contributor

CC @panjf2000

@ianlancetaylor
Copy link
Contributor

Marking as release blocker since we shouldn't get a sendfile error from an io.Copy call.

I haven't tested earlier Go releases.

@ianlancetaylor
Copy link
Contributor

With Go 1.22 the program works as expected.

With Go 1.23 the program exits immediately with no error, as reported by this bug report.

@ianlancetaylor
Copy link
Contributor

In Go 1.23 the program fails because it uses Stat to get the size of standard input, comes up with 0, and proceeds to copy 0 bytes.

In Go 1.24 it makes it into calling sendfile, which fails with the error ESOCKTNOSUPPORT, which is not handled by internal/poll.sendFile.

@ianlancetaylor
Copy link
Contributor

@gopherbot Please open backport to 1.23

This is a simple program that broke with some sendfile work in the Go 1.23 release. Earlier releases are OK.

@ianlancetaylor ianlancetaylor added this to the Go1.24 milestone Dec 11, 2024
@gopherbot
Copy link
Contributor

Backport issue(s) opened: #70789 (for 1.23).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@ianlancetaylor
Copy link
Contributor

CC @neild

@ianlancetaylor
Copy link
Contributor

Sorry, it's not ESOCKTNOSUPPORT, it's ENOTSUP.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/635396 mentions this issue: internal/poll: in SendFile treat ENOTSUP like EOPNOTSUPP

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/635397 mentions this issue: [release-branch.go1.23] net: don't use sendfile for irregular files; handle EOPNOTSUPP/ENOTSUP

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. FixPending Issues that have a fix which has not yet been reviewed or submitted. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Dec 12, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/635815 mentions this issue: syscall: on freebsd-386 only update written for certain errors

gopherbot pushed a commit that referenced this issue Dec 12, 2024
Testing on the freebsd-386 gomote seems to show that sendfile returns
a non-zero number of bytes written even when it returns EINVAL.
This confuses the caller. Change the Go code to only return non-zero
on success or EINTR or EAGAIN, which are the only cases where the
man page says that sendfile updates the number of bytes.

For #70763

Change-Id: Icc04e6286b5b29a2029237711d50fe4973234f0a
Reviewed-on: https://go-review.googlesource.com/c/go/+/635815
Reviewed-by: Ian Lance Taylor <[email protected]>
Commit-Queue: Ian Lance Taylor <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
@dr2chase dr2chase added the Critical A critical problem that affects the availability or correctness of production systems built using Go label Dec 18, 2024
gopherbot pushed a commit that referenced this issue Dec 18, 2024
…handle EOPNOTSUPP/ENOTSUP

This is not a cherry pick, because the code has changed on tip.

For #70763
Fixes #70789

Change-Id: If9fcfee17e86a746cf8c72293dc34f80b430f6e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/635397
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
yangjuncode pushed a commit to yangjuncode/go that referenced this issue Dec 27, 2024
…handle EOPNOTSUPP/ENOTSUP

This is not a cherry pick, because the code has changed on tip.

For golang#70763
Fixes golang#70789

Change-Id: If9fcfee17e86a746cf8c72293dc34f80b430f6e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/635397
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
mpminardi pushed a commit to tailscale/go that referenced this issue Jan 28, 2025
…handle EOPNOTSUPP/ENOTSUP

This is not a cherry pick, because the code has changed on tip.

For golang#70763
Fixes golang#70789

Change-Id: If9fcfee17e86a746cf8c72293dc34f80b430f6e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/635397
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Critical A critical problem that affects the availability or correctness of production systems built using Go FixPending Issues that have a fix which has not yet been reviewed or submitted. NeedsFix The path to resolution is known, but the work has not been done. OS-Darwin release-blocker
Projects
None yet
Development

No branches or pull requests

7 participants