mdlayher / vsock

Package vsock provides access to Linux VM sockets (AF_VSOCK) for communication between a hypervisor and its virtual machines. MIT Licensed.
MIT License
336 stars 65 forks source link

listener_linux.go:32:28: not enough arguments in call to l.c.Accept #51

Closed ChiaoY closed 1 year ago

ChiaoY commented 1 year ago

Hi, I was using go get -u github.com/u-root/cpu/... command, it cloned this repo, then showed the error message as below:

chiao@Ubuntu2204VM:~/git/linuxboot/mainboards/ampere/jade$ go get -u github.com/u-root/cpu/...
# github.com/mdlayher/vsock
/home/chiao/go/src/github.com/mdlayher/vsock/listener_linux.go:32:28: not enough arguments in call to l.c.Accept
        have (number)
        want (context.Context, int)

I've changed my golang version to 1.18.7 as the same as this repo's CI, but the error occurred again. I cd into the repo dir and go test. Failed with same error.

chiao@Ubuntu2204VM:~/go/src/github.com/mdlayher/vsock$ go test
# github.com/mdlayher/vsock [github.com/mdlayher/vsock.test]
./listener_linux.go:32:28: not enough arguments in call to l.c.Accept
        have (number)
        want (context.Context, int)
FAIL    github.com/mdlayher/vsock [build failed]

Here's my env:

chiao@Ubuntu2204VM:~/git/linuxboot/mainboards/ampere/jade$ uname -a
Linux Ubuntu2204VM 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
chiao@Ubuntu2204VM:~/Downloads$ go env
GO111MODULE="off"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/chiao/.cache/go-build"
GOENV="/home/chiao/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/chiao/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/chiao/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.7"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1116994110=/tmp/go-build -gno-record-gcc-switches"
mdlayher commented 1 year ago

I can't reproduce with Go 1.18 or Go 1.19 on a fresh clone of latest main, v1.2.0:

matt@matt-3:~/src/github.com/mdlayher/vsock$ go version
go version go1.19.1 linux/amd64
matt@matt-3:~/src/github.com/mdlayher/vsock$ go build ./...
matt@matt-3:~/src/github.com/mdlayher/vsock$ go test ./...
ok      github.com/mdlayher/vsock       0.431s
?       github.com/mdlayher/vsock/cmd/vscp      [no test files]
?       github.com/mdlayher/vsock/internal/vsutil       [no test files]
matt@matt-3:~/src/github.com/mdlayher/vsock$ go1.18 build ./...
matt@matt-3:~/src/github.com/mdlayher/vsock$ go1.18 test ./...
ok      github.com/mdlayher/vsock       (cached)
?       github.com/mdlayher/vsock/cmd/vscp      [no test files]
?       github.com/mdlayher/vsock/internal/vsutil       [no test files]

If I had to guess, there may be some sort of module issue. I added context support to the underlying socket library recently (which does not yet have a stable API) and made changes to some of my other packages to fix it up. I would guess that something else in the u-root dependencies needs to be updated too.

mdlayher commented 1 year ago
chiao@Ubuntu2204VM:~/Downloads$ go env
GO111MODULE="off"

Yep, that probably explains it. I don't think this is an issue with this library and am going to close this out. Feel free to reply again if you run into more issues.

ChiaoY commented 1 year ago

I've tested with GO111MODULE=on, and it worked. Thank you for your help. I am now able to go1.18 build mdlayher/vsock directly.

However, the original command "go get -u github.com/u-root/cpu/..." still can't work correctly. With GO111MODULE=on, I get:

chiao@Thinkbook14:~/git/linuxboot/mainboards/ampere/jade$ GO111MODULE=on go get -u github.com/u-root/cpu/...
go: go.mod file not found in current directory or any parent directory.
        'go get' is no longer supported outside a module.
        To build and install a command, use 'go install' with a version,
        like 'go install example.com/cmd@latest'
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.

With GO111MODULE=auto or GO111MODULE=off I get the original error

chiao@Thinkbook14:~/git/linuxboot/mainboards/ampere/jade$ GO111MODULE=auto go get -u github.com/u-root/cpu/...
# github.com/mdlayher/vsock
/home/chiao/go/src/github.com/mdlayher/vsock/listener_linux.go:32:28: not enough arguments in call to l.c.Accept
        have (number)
        want (context.Context, int)
chiao@Thinkbook14:~/git/linuxboot/mainboards/ampere/jade$ GO111MODULE=off go get -u github.com/u-root/cpu/...
# github.com/mdlayher/vsock
/home/chiao/go/src/github.com/mdlayher/vsock/listener_linux.go:32:28: not enough arguments in call to l.c.Accept
        have (number)
        want (context.Context, int)

I have to manually build mdlayher/vsock, but it seems fine for now.

Which might be some kind of misconducting switching between GOMODULE and GOPATH?

u-root/cpu imports lots of repos go.mod file and others works fine whether GO111MODULE is on, off, or auto.

I apologize that I am not familiar with Golang at all. Therefore, I'm not criticizing, but just sharing my observation. Just like to provide more information and feedback to you.

Many thanks for your help and testing time in very short time again!!!

tinhnampere commented 1 year ago

Hi Chiao,

I am facing the same problem. "go get" is deprecated from go 1.17, you can use "go install" instead. :) but you also need to get the source code. Don't forget to set GO111MODULE=auto, it works for me

diff --git a/mainboards/ampere/jade/Makefile b/mainboards/ampere/jade/Makefile
index 5247266..8e8bc4f 100644
--- a/mainboards/ampere/jade/Makefile
+++ b/mainboards/ampere/jade/Makefile
@@ -21,7 +21,7 @@ flashinitramfs.cpio.lzma: flashinitramfs.cpio
        lzma -f -k $<

 flashinitramfs.cpio: Makefile
-       GO111MODULE=off GOARCH=arm64 u-root -uinitcmd=systemboot -o $@ core \
+       GOARCH=arm64 u-root -uinitcmd=systemboot -o $@ core \
                github.com/u-root/u-root/cmds/boot/systemboot \
                github.com/u-root/u-root/cmds/boot/localboot \
                github.com/u-root/u-root/cmds/boot/fbnetboot \
@@ -36,7 +36,7 @@ flashinitramfs.cpio: Makefile
 # It depends on the kernel setting the IP address.
 # You need ip=dhcp OR ip=fixed.ip.address.here in the command line
 cpu.cpio.lzma: Makefile
-       GO111MODULE=off GOARCH=arm64 go run github.com/u-root/u-root -o cpu.cpio -build=bb -initcmd=cpud -files ~/.ssh/cpu_rsa.pub:key.pub \
+       GOARCH=arm64 go run github.com/u-root/u-root -o cpu.cpio -build=bb -initcmd=cpud -files ~/.ssh/cpu_rsa.pub:key.pub \
                -defaultsh="" \
                github.com/u-root/cpu/cmds/cpud
        lzma -f -k cpu.cpio
@@ -46,7 +46,7 @@ cpu.cpio.lzma: Makefile
 # It depends on the kernel setting the IP address.
 # You need ip=dhcp OR ip=fixed.ip.address.here in the command line
 sshd.cpio.lzma:  Makefile
-       GO111MODULE=off GOARCH=arm64 go run github.com/u-root/u-root -o sshd.cpio -build=bb \
+       GOARCH=arm64 go run github.com/u-root/u-root -o sshd.cpio -build=bb \
                -uinitcmd=/bbin/sshd \
                -files class_key.pub:authorized_keys \
                -files classhostkey:id_rsa \
@@ -79,8 +79,9 @@ getkernel:
        (cd linux && ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make tinyconfig)

 geturoot:
-       go get -u github.com/u-root/u-root
-       go get -u github.com/u-root/cpu/...
+       go get -d github.com/u-root/u-root
+       go get -d github.com/u-root/cpu/...
+       go install github.com/u-root/u-root@latest
ChiaoY commented 1 year ago

Hi, tinhnampere Thank you for the test It seems that "go get -d github.com/u-root/cpu/..." works because the command only download the package without building it. I tried "make cpu.cpio.lzma" after "go get -d" which needs to build cpu package, and still got the error message.

tinhnampere commented 1 year ago

Yes, it just downloads the source code, the executables were downloaded by "go install" i have modified the build target like below

cpu.cpio.lzma: Makefile
         GOARCH=arm64 u-root -o cpu.cpio -build=bb -initcmd=cpud -files ~/.ssh/cpu_rsa.pub:key.pub \
                -defaultsh="" \
                github.com/u-root/cpu/cmds/cpud
        lzma -f -k cpu.cpio

build successfully with go 1.18

+ make -C  linuxboot/mainboards/ampere/jade geturoot cpu.cpio.lzma ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-
make: Entering directory 'linuxboot/mainboards/ampere/jade'
go get -d github.com/u-root/u-root
go get -d github.com/u-root/cpu/...
go install github.com/u-root/u-root@latest
go: downloading github.com/u-root/u-root v0.10.0
go: downloading github.com/u-root/gobusybox/src v0.0.0-20220728145311-85dc1fd1bc75
go: downloading golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d
go: downloading github.com/dustin/go-humanize v1.0.0
go: downloading github.com/pierrec/lz4/v4 v4.1.14
go: downloading github.com/u-root/uio v0.0.0-20220204230159-dac05f7d2cb4
go: downloading github.com/google/goterm v0.0.0-20200907032337-555d40f16ae2
go: downloading golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
go: downloading golang.org/x/tools v0.1.11
GOARCH=arm64 u-root -o cpu.cpio -build=bb -initcmd=cpud -files ~/.ssh/cpu_rsa.pub:key.pub \
        -defaultsh="" \
        github.com/u-root/cpu/cmds/cpud
14:24:33 Build environment: GOARCH=arm64 GOOS=linux GOROOT=toolchain/go GOPATH=toolchain/gosource CGO_ENABLED=0
14:24:33 WARNING: You are not using one of the recommended Go versions (have = go1.18.4, recommended = [go1.17]).
                        Some packages may not compile.
                        Go to https://golang.org/doc/install to find out how to install a newer version of Go,
                        or use https://godoc.org/golang.org/dl/go1.17 to install an additional version of Go.
14:24:33 NOTE: building with the new gobusybox; to get the old behavior check out commit 8b790de
14:24:47 Successfully built "cpu.cpio" (size 3608608).
lzma -f -k cpu.cpio