chipmk / docker-mac-net-connect

Connect directly to Docker-for-Mac containers via IP address 🐳 💻
MIT License
414 stars 44 forks source link

invalid reference to syscall.recvmsg #39

Closed mtx2d closed 1 month ago

mtx2d commented 2 months ago

Hi Team, I fail to install this from brew with:

 brew install chipmk/tap/docker-mac-net-connect

Running into the following error:

# github.com/chipmk/docker-mac-net-connect
link: golang.org/x/net/internal/socket: invalid reference to syscall.recvmsg
Details ``` ➜ ~ brew install chipmk/tap/docker-mac-net-connect ==> Auto-updating Homebrew... Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`). ==> Fetching chipmk/tap/docker-mac-net-connect ==> Downloading https://github.com/chipmk/docker-mac-net-connect/archive/refs/tags/v0.1.2.tar.gz Already downloaded: /Users/mqiu/Library/Caches/Homebrew/downloads/be6ddea4c4a482e7843b5d9af1de1ea1fc218b83ea19a6b12b15081e2ce8983f--docker-mac-net-connect-0.1.2.tar.gz ==> Installing docker-mac-net-connect from chipmk/tap ==> make VERSION=v0.1.2 build-go Last 15 lines from /Users/mqiu/Library/Logs/Homebrew/docker-mac-net-connect/01.make: 2024-08-18 06:22:03 +0000 make VERSION=v0.1.2 build-go fatal: not a git repository (or any of the parent directories): .git go build -ldflags "-s -w -X github.com/chipmk/docker-mac-net-connect/version.Version=v0.1.2 -X github.com/chipmk/docker-mac-net-connect/version.SetupImage=ghcr.io/chipmk/docker-mac-net-connect/setup" github.com/chipmk/docker-mac-net-connect # github.com/chipmk/docker-mac-net-connect link: golang.org/x/net/internal/socket: invalid reference to syscall.recvmsg make: *** [build-go] Error 1 If reporting this issue please do so at (not Homebrew/brew or Homebrew/homebrew-core): https://github.com/chipmk/homebrew-tap/issues ```

My golang version is:

➜  ~ go version
go version go1.23.0 darwin/arm64
cedorman commented 2 months ago

I am getting the same error, same version of go. I found the following: https://github.com/bettercap/bettercap/issues/1106

It says: "It seems that in referenced package golang.org/x/net/internal/socket there is a now forbidden //go:linkname reference to syscall.recvmsg." Googling around turns up several other go programs that have the same error, but no fixes yet.

btalbot commented 2 months ago

Go 1.23 broke access to internal symbols. Looks like a new linker flag -checklinkname=0 can allow access for "testing" but I'd assume that will go away in a bit. https://go.dev/doc/go1.23#linker

btalbot commented 2 months ago

To work around this locally I tried a few things. Installing an older go version viabrew install go@1.22 and then attempting brew install --ignore-dependencies chipmk/tap/docker-mac-net-connect ends with an error about not being a .git or something. I tried a few work arounds but I couldn't get the build to work with go@1.22 when also using homebrew. Manual build using go@1.22 is fine.

This patch of the homebrew formula does work though and maybe good enough until @chipmk can look into this. Clone the chipmk/homebrew-taps repo, apply the patch, and then install locally via brew install --build-from-source ./homebrew-tap/Formula/docker-mac-net-connect.rb

diff --git a/Formula/docker-mac-net-connect.rb b/Formula/docker-mac-net-connect.rb
index 1ac59c6..fd515ba 100644
--- a/Formula/docker-mac-net-connect.rb
+++ b/Formula/docker-mac-net-connect.rb
@@ -11,6 +11,8 @@ class DockerMacNetConnect < Formula

   depends_on "go" => :build

+  patch :p1, :DATA
+
   def install
     if ENV["HOMEBREW_GOPROXY"]
       ENV["GOPROXY"] = ENV["HOMEBREW_GOPROXY"]
@@ -41,3 +43,18 @@ class DockerMacNetConnect < Formula
     system "false"
   end
 end
+
+__END__
+diff --git a/Makefile b/Makefile
+index 2021ae7..d9c03fe 100644
+--- a/Makefile
++++ b/Makefile
+@@ -1,7 +1,7 @@
+ PROJECT         := github.com/chipmk/docker-mac-net-connect
+ SETUP_IMAGE     := ghcr.io/chipmk/docker-mac-net-connect/setup
+ VERSION         := $(shell git describe --tags)
+-LD_FLAGS        := -X ${PROJECT}/version.Version=${VERSION} -X ${PROJECT}/version.SetupImage=${SETUP_IMAGE}
++LD_FLAGS        := -checklinkname=0 -X ${PROJECT}/version.Version=${VERSION} -X ${PROJECT}/version.SetupImage=${SETUP_IMAGE}
+
+ run:: build-docker run-go
+ build:: build-docker build-go
cedorman commented 2 months ago

Thank you btalbot. Based on your comment, I made a different workaround:

Doing this causes you to lose the fact that it is a service (since it entirely skips homebrew) but honestly I am not sure that I want it to be a service anyway.

thiagotgo90 commented 2 months ago

Hi

I made some progress, but couldn't install. I uninstall go@1.23 and installed go@1.22. After that I ran

brew install --ignore-dependencies -g chipmk/tap/docker-mac-net-connect

but it failed with a new error:

Initialized empty Git repository in /private/tmp/docker-mac-net-connect-20240824-37577-x4dobe/docker-mac-net-connect-0.1.2/.git/
==> make VERSION=v0.1.2 build-go
Last 15 lines from /Users/work/Library/Logs/Homebrew/docker-mac-net-connect/01.make:
2024-08-24 16:58:45 +0000

make
VERSION=v0.1.2
build-go

fatal: No names found, cannot describe anything.
go build -ldflags "-s -w -X github.com/chipmk/docker-mac-net-connect/version.Version=v0.1.2 -X github.com/chipmk/docker-mac-net-connect/version.SetupImage=ghcr.io/chipmk/docker-mac-net-connect/setup" github.com/chipmk/docker-mac-net-connect
/bin/sh: go: command not found
make: *** [build-go] Error 127

If reporting this issue please do so at (not Homebrew/brew or Homebrew/homebrew-core):
  https://github.com/chipmk/homebrew-tap/issues
brunoboreli commented 2 months ago

@btalbot Thank you man! You just saved me!

recap commented 1 month ago

Also when digging around for a solution for this I discovered Docker Desktop has a feature to create a bridge on the host and eth1 on the VM. It is the "Use kernel networking for UDP" in settings->resources->network. With this enabled you only need to create routes on the MacOS host for the docker subnets. I created a small bash script with no dependencies to just do that here (https://github.com/recap/docker-mac-routes)

btalbot commented 1 month ago

Sadly, it looks like this repo is no longer maintained so the solution along the lines that @recap has seems like the best option going forward.

jagregory commented 1 month ago

I just used @recap's approach successfully with the latest version of Docker Desktop. ❤️

gregnr commented 1 month ago

Hey folks, apologies for the delay. I've fixed this now in v0.1.3 - the issue was caused by a dependency (github.com/mdlayher/netlink) referencing the internal socket APIs which was thankfully changed in a newer version.

You can update to the latest version of docker-mac-net-connect by running:

brew reinstall chipmk/tap/docker-mac-net-connect

then reloading the background service:

sudo brew services restart chipmk/tap/docker-mac-net-connect

or if you prefer to run the service manually:

sudo /opt/homebrew/opt/docker-mac-net-connect/bin/docker-mac-net-connect

I tested the new version and everything seems to work correctly. Please do let me know though if this doesn't work for you and we'll keep digging.

thiagotgo90 commented 1 month ago

Hey Greg,

Thank you very much for help here. Have a nice weekend.