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: UnixListener.Close can be dangerous #17131

Closed
LK4D4 opened this issue Sep 15, 2016 · 2 comments
Closed

net: UnixListener.Close can be dangerous #17131

LK4D4 opened this issue Sep 15, 2016 · 2 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@LK4D4
Copy link
Contributor

LK4D4 commented Sep 15, 2016

Please answer these questions before submitting your issue. Thanks!

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

go version devel +7f583a4 Wed Sep 14 13:28:13 2016 +0000 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/home/moroz/go"
GOTOOLDIR="/home/moroz/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build862845019=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

What did you do?

Here is simple program which shows the problem:
https://gist.github.com/7595f6db11d7202cb3fa12e64a862c61

What did you expect to see?

UnixListener.Close() unlinks unix-socket only once.

What did you see instead?

UnixListener.Close() unconditionally unlinks unix-socket file - with closed listener you can unlink it again, Close will return an error, but file will be deleted anyway.

I've encountered this problem when worked with grpc, which supposed that it's safe to call Close() multiple times and actually I thought so, too.
I wonder if it's too bad to have sync.Once there.
Thanks!

@mattn
Copy link
Member

mattn commented Sep 16, 2016

Try to put @ prefix to open the unix domain socket. https://play.golang.org/p/lcNOjpfOvM

BTW, I don't see this behavior on https://golang.org/pkg/net/#Listen or https://golang.org/pkg/net/#UnixListener . This is documentation bug.

@quentinmit quentinmit added this to the Go1.8 milestone Oct 3, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 7, 2016
@gopherbot
Copy link

CL https://golang.org/cl/32098 mentions this issue.

@golang golang locked and limited conversation to collaborators Oct 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants