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

net: Conn.Write() does not detect dropped TCP connection on the first attempt #20553

Closed
vbox opened this issue Jun 2, 2017 · 2 comments
Closed

Comments

@vbox
Copy link

vbox commented Jun 2, 2017

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

go version go1.8.3 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/kvs/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build565879858=/tmp/go-bui
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

A dropped TCP connection does not get detected on the first Write(), but detected on subsequent ones.

Steps to reproduce:

  1. Compile Go client - https://gist.github.com/vbox/d6b8d3f431fd5195846929ee9659ed25

  2. Open TCP socket with nc:
    nc -kl 5555

  3. Start client binary, and immediately after client has established connection, kill nc. The client will attempt to write to a dropped connection, but no error is generated.

What did you expect to see?

$ ./client
connection established
Write to server failed: write tcp 127.0.0.1:48176->127.0.0.1:5555: write: broken pipe

What did you see instead?

$ ./client
connection established
writen to server = Halo
Write to server failed: write tcp 127.0.0.1:48176->127.0.0.1:5555: write: broken pipe

@davecheney
Copy link
Contributor

davecheney commented Jun 2, 2017 via email

@mikioh
Copy link
Contributor

mikioh commented Jun 3, 2017

Your test code doesn't guarantee that the first write call that invokes some functionality inside the kernel has got a closed state of the underlying connection before it returns to the test code. On linux net/ipv4/tcp.c and tcp_output.c describe how the write system call interacts with the TCP implementation.

@mikioh mikioh closed this as completed Jun 3, 2017
@golang golang locked and limited conversation to collaborators Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants