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: [WSL2] listen unix /tmp/echo.sock: bind: A socket operation encountered a dead network. #44797

Closed
r-novel opened this issue Mar 4, 2021 · 8 comments

Comments

@r-novel
Copy link

@r-novel r-novel commented Mar 4, 2021

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

$ go version
go version go1.16 windows/amd64

Does this issue reproduce with the latest release?

Not sure.

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

WSL2, Windows 10 19042.804

$ uname -a
Linux NOV 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 GNU/Linux
go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Nov\AppData\Local\go-build
set GOENV=C:\Users\Nov\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Nov\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Nov\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Nov\AppData\Local\Temp\go-build3936160155=/tmp/go-build -gno-record-gcc-switches

What did you do?

I try to create an HTTP server over UNIX socket following the code below:
https://play.golang.org/p/y_9ERHHbBxI

What did you expect to see?

I want to see running server app.

What did you see instead?

2021/03/05 01:12:19 listen unix /tmp/echo.sock: bind: A socket operation encountered a dead network.
@davecheney
Copy link
Contributor

@davecheney davecheney commented Mar 4, 2021

Does /tmp/echo.sock exist before you ran the program? Maybe a previous version left it around?

@r-novel
Copy link
Author

@r-novel r-novel commented Mar 4, 2021

@davecheney Look like, it exists:

$ ls -lah /tmp/ | grep 'echo'
srwxr-xr-x  1 nov nov 0 Mar  5 00:36 echo.sock
@davecheney
Copy link
Contributor

@davecheney davecheney commented Mar 4, 2021

I don't think there is any thing left to do here, this doesn't look like a defect in Go.

@r-novel
Copy link
Author

@r-novel r-novel commented Mar 4, 2021

Seems it doesn't relevant to WSL-specific things.

netcat works fine:

listener:

$ nc -Ul /tmp/echo.sock

client:

$ echo "data" | nc -U /tmp/echo.sock
@davecheney
Copy link
Contributor

@davecheney davecheney commented Mar 4, 2021

Can you strace the nc process, maybe it unlinks the socket before binding to it?

@r-novel
Copy link
Author

@r-novel r-novel commented Mar 5, 2021

@davecheney Yes, it unlinks.

$ strace nc -Ul /tmp/echo.sock
strace log
execve("/bin/nc", ["nc", "-Ul", "/tmp/echo.sock"], [/* 54 vars */]) = 0
brk(NULL)                               = 0x555cf0c03000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6587551000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=67635, ...}) = 0
mmap(NULL, 67635, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f6587540000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libbsd.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\3203\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=84200, ...}) = 0
mmap(NULL, 2183248, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f658711b000
mprotect(0x7f658712e000, 2097152, PROT_NONE) = 0
mmap(0x7f658732e000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x13000) = 0x7f658732e000
mmap(0x7f6587330000, 80, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f6587330000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libresolv.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p9\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=84848, ...}) = 0
mmap(NULL, 2189896, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6586f04000
mprotect(0x7f6586f18000, 2093056, PROT_NONE) = 0
mmap(0x7f6587117000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x13000) = 0x7f6587117000
mmap(0x7f6587119000, 6728, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f6587119000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\4\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1689360, ...}) = 0
mmap(NULL, 3795296, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6586b65000
mprotect(0x7f6586cfa000, 2097152, PROT_NONE) = 0
mmap(0x7f6586efa000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x195000) = 0x7f6586efa000
mmap(0x7f6586f00000, 14688, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f6586f00000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340 \0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=31744, ...}) = 0
mmap(NULL, 2128832, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f658695d000
mprotect(0x7f6586964000, 2093056, PROT_NONE) = 0
mmap(0x7f6586b63000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f6586b63000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0Pa\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=135440, ...}) = 0
mmap(NULL, 2212936, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f6586740000
mprotect(0x7f6586758000, 2093056, PROT_NONE) = 0
mmap(0x7f6586957000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7f6586957000
mmap(0x7f6586959000, 13384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f6586959000
close(3)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f658753e000
arch_prctl(ARCH_SET_FS, 0x7f658753f440) = 0
mprotect(0x7f6586efa000, 16384, PROT_READ) = 0
mprotect(0x7f6586957000, 4096, PROT_READ) = 0
mprotect(0x7f6586b63000, 4096, PROT_READ) = 0
mprotect(0x7f6587117000, 4096, PROT_READ) = 0
mprotect(0x7f658732e000, 4096, PROT_READ) = 0
mprotect(0x555cef97b000, 4096, PROT_READ) = 0
mprotect(0x7f6587554000, 4096, PROT_READ) = 0
munmap(0x7f6587540000, 67635)           = 0
set_tid_address(0x7f658753f710)         = 324
set_robust_list(0x7f658753f720, 24)     = 0
rt_sigaction(SIGRTMIN, {sa_handler=0x7f6586745bd0, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x7f65867510c0}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {sa_handler=0x7f6586745c60, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7f65867510c0}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f6586b98060}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
socket(AF_UNIX, SOCK_STREAM, 0)         = 3
unlink("/tmp/echo.sock")                = 0
bind(3, {sa_family=AF_UNIX, sun_path="/tmp/echo.sock"}, 16) = 0
listen(3, 5)                            = 0
accept(3,
@davecheney
Copy link
Contributor

@davecheney davecheney commented Mar 5, 2021

Maybe you can change your code to unlink the socket before trying to open it.

@r-novel
Copy link
Author

@r-novel r-novel commented Mar 6, 2021

@davecheney Yes! I've understood what happened.

tl;dr don't run the application from mounted Windows FS (/mnt/c/Users/bla-bla-bla) using WSL.

I've moved source code to WSL /home and application has started and worked correctly.

Thanks for help.

Closed.

@r-novel r-novel closed this Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants