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

Comments

Projects
None yet
4 participants
@LK4D4
Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

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.

@gopherbot

This comment has been minimized.

Copy link

commented Oct 27, 2016

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

@gopherbot gopherbot closed this in 13558c4 Oct 28, 2016

@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.
You can’t perform that action at this time.