go: runtime: multi-arch build via qemu fails to exec go binary

Go version

go version 1.23.0 linux/arm64

Output of go env in your module/workspace:

I'm unable to provide the output of `go env` as it fails with the same telemetry fork/exec error.

What did you do?

Our automated image build process fails to perform any step that invokes the go binary with the following error:

can't start telemetry child process: fork/exec /usr/local/go/bin/go: invalid argument

The Dockerfile is here, and is being built via a script that invokes docker buildx with multiple platforms, like:

docker buildx build --platform=linux/amd64,linux/arm64 --file 1.23/Dockerfile

It seems that there is something inherent in the qemu arm64 environment that renders go unable to fork itself to complete the telemetry setup. I’m fairly confident it’s something specific to the 1.23 release as 1.22.6 builds successfully using the same setup today.

What did you see happen?

Failures to invoke any go command

What did you expect to see?

A successful install and configuration of go 1.23.0 in a multi-arch docker build.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 16
  • Comments: 57 (39 by maintainers)

Commits related to this issue

Most upvoted comments

Yeah, I didn’t think closely enough about this initially. I thought the code starting the telemetry subprocess was doing something special, but the real bug here is that any os.StartProcess / os/exec is broken.

I have the same problem. I can see the error can't start telemetry child process in my log, but as you said, it is not fatal, so it is working properly.

Unfortunately, now I see the same error @the-hotmann is referring to when I try to use go install or go run. That error is fatal (exit code 1).

$ go run ./test.go
can't start telemetry child process: fork/exec /usr/local/go/bin/go: invalid argument
go: error obtaining buildID for go tool compile: fork/exec /usr/local/go/pkg/tool/linux_arm64/compile: invalid argument
go: error obtaining buildID for go tool compile: fork/exec /usr/local/go/pkg/tool/linux_arm64/compile: invalid argument
go: error obtaining buildID for go tool compile: fork/exec /usr/local/go/pkg/tool/linux_arm64/compile: invalid argument
go: error obtaining buildID for go tool compile: fork/exec /usr/local/go/pkg/tool/linux_arm64/compile: invalid argument
go: error obtaining buildID for go tool compile: fork/exec /usr/local/go/pkg/tool/linux_arm64/compile: invalid argument
go: error obtaining buildID for go tool compile: fork/exec /usr/local/go/pkg/tool/linux_arm64/compile: invalid argument

$ cat test.go
package main

import "fmt"

func main() {
        fmt.Println("Hello world");
}

$ arch
aarch64

Here is the output of go install:

$ go install github.com/amacneil/dbmate/v2@v2.4.0
go: downloading github.com/amacneil/dbmate/v2 v2.4.0
go: downloading github.com/joho/godotenv v1.5.1
go: downloading github.com/urfave/cli/v2 v2.25.5
go: downloading github.com/lib/pq v1.10.9
go: downloading github.com/go-sql-driver/mysql v1.7.1
go: downloading github.com/ClickHouse/clickhouse-go/v2 v2.10.0
go: downloading github.com/ClickHouse/ch-go v0.56.0
go: downloading github.com/andybalholm/brotli v1.0.5
go: downloading github.com/pkg/errors v0.9.1
go: downloading go.opentelemetry.io/otel/trace v1.16.0
go: downloading go.opentelemetry.io/otel v1.16.0
go: downloading github.com/google/uuid v1.3.0
go: downloading github.com/paulmach/orb v0.9.2
go: downloading github.com/shopspring/decimal v1.3.1
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.2
go: downloading github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673
go: downloading github.com/russross/blackfriday/v2 v2.1.0
go: downloading github.com/go-faster/city v1.0.1
go: downloading github.com/go-faster/errors v0.6.1
go: downloading github.com/klauspost/compress v1.16.5
go: downloading github.com/pierrec/lz4/v4 v4.1.17
go: downloading github.com/segmentio/asm v1.2.0
go: downloading golang.org/x/sys v0.8.0
go: error obtaining buildID for go tool compile: fork/exec /usr/local/go/pkg/tool/linux_arm64/compile: invalid argument
go: error obtaining buildID for go tool compile: fork/exec /usr/local/go/pkg/tool/linux_arm64/compile: invalid argument
go: error obtaining buildID for go tool compile: fork/exec /usr/local/go/pkg/tool/linux_arm64/compile: invalid argument
go: error obtaining buildID for go tool compile: fork/exec /usr/local/go/pkg/tool/linux_arm64/compile: invalid argument
go: error obtaining buildID for go tool compile: fork/exec /usr/local/go/pkg/tool/linux_arm64/compile: invalid argument
go: error obtaining buildID for go tool compile: fork/exec /usr/local/go/pkg/tool/linux_arm64/compile: invalid argument

To reproduce:

$ podman run -it --rm --platform linux/arm64 golang:1.23.1
# printf "package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello world\");\n}\n" > test.go
# go run ./test.go

EDIT: missing --platform linux/arm64 in the command (lost in the copy-paste)

Apologies for that, there was confusion on the status of the backport because this issue wasn’t closed when https://go.dev/cl/592078 went in. Closing now, as there are no more known issues (other than the maybe-Google-specifc https://github.com/golang/go/issues/69259#issuecomment-2376755781).

FWIW, Debian bookworm has QEMU 7.2 in its repository, which is probably why so many people have hit this.

To reproduce this issue:

go.mod:

module example.com/app

go 1.23

main.go:

package main

import (
        "fmt"
        "os"
        "os/exec"
)

func main() {
        if os.Getenv("TEST_SUBPROCESS") == "1" {
                fmt.Println("Hello from child")
                return
        }

        exe, err := os.Executable()
        if err != nil {
                panic(err)
        }

        cmd := exec.Command(exe)
        cmd.Env = append(cmd.Environ(), "TEST_SUBPROCESS=1")
        cmd.Stdout = os.Stdout
        cmd.Stderr = os.Stderr
        if err := cmd.Run(); err != nil {
                panic(err)
        }
}

Dockerfile:

FROM debian:bookworm

RUN apt-get update && apt-get install -y qemu-user-static

COPY app app

CMD ["qemu-x86_64-static", "app"]
$ go build   # outside the container
$ docker build -t issue68976_qemu .
$ docker run --rm -it issue68976_qemu

Without https://go.dev/cl/592078:

panic: fork/exec /app: invalid argument

goroutine 1 [running]:
main.main()
        /usr/local/google/home/mpratt/Downloads/issue68976_qemu/main.go:25 +0x17a

With https://go.dev/cl/592078:

Hello from child

Ah, sorry for the misunderstanding.

@tianon Could you try cherry-picking https://go.dev/cl/592077 and https://go.dev/cl/592078 to see if they fix the issue?

You can get a cherry pick command from Gerrit from the upper right “…” menu -> “Download patch”.

Thanks for the logs. The offending call is:

1 pidfd_open(1,0) = 9
1 pidfd_send_signal(9,0,NULL,0) = 0
1 clone(CLONE_VM|CLONE_VFORK|0x1011,child_stack=0x0000000000000000,parent_tidptr=0x00000040002872b8,tls=0x0000000000000000,child_tidptr=0x0000000000000000) = -1 errno=22 (Invalid argument)

Flag 0x1000 is CLONE_PIDFD. I’d assume that is the flag QEMU is complaining about.

What version of QEMU are you using? CLONE_PIDFD support appears to be added in https://github.com/qemu/qemu/commit/895ce8bb534e66ca418dea62ae67a92dccafb2e1 (QEMU 8.0).

We test that syscalls pidfd_open and pidfd_send_signal work before attempting to use CLONE_PIDFD. In Linux, support of those guarantees support for CLONE_PIDFD, but perhaps not in QEMU?

Moved to Go1.24 milestone since this need to be fixed on the main branch first (for Go 1.24), before being considered for backporting. Please use the usual process (https://go.dev/wiki/MinorReleases) to create a separate backport tracking issue in the Go1.23.1 milestone.

@findleyr It’s important that issues in the minor milestones are the backport kind with a CherryPickCandidate label, otherwise we might miss them in our release meeting review. Thanks.

I switched from multiarch/qemu-user-static (QEMU 7.2) to a custom image with QEMU 9.1 from debian:unstable and my multi-arch builds worked seamlessly. Uploaded here for reference: https://github.com/andreadelfino/qemu-user-static

It’s probably just a workaround, and I still need to extensively test to see if everything downstream works as before.

Turning off telemetry doesn’t fix it – it’s literally os/exec itself that’s broken (so if it isn’t telemetry triggering it, it’ll be forking the compile process instead), as noted in the last few comments before yours. 🙈

is it possible to use lower version of golang to avoid this error?

This is a 1.23 / dev 1.24 bug. Yes, if one is running into this (as I did), they could consider downgrading to 1.22 until 1.23/dev 1.24 is fixed.

Turning off telemetry doesn’t fix it – it’s literally os/exec itself that’s broken (so if it isn’t telemetry triggering it, it’ll be forking the compile process instead), as noted in the last few comments before yours. 🙈

@tianon It sounds like this is fixed? I’ll mark this closed.

Tried again, because I noticed I was setting GOHOST* 🙃

Got a successful build with those two CLs (cherry-picked exactly as described in my comment above), and the build appears to work correctly:

$ /usr/local/go/bin/linux_arm64/go version
go version devel go1.24-d53c47bd71a Thu Aug 29 16:55:15 2024 +0000 linux/arm64

Yes, I mean this issue shouldn’t be closed by that. This issue affects more than just telemetry.

It looks like pidfd_open, etc were added in https://github.com/qemu/qemu/commit/cc054c6f139cf54ce8fbefd6fd536f50b4cba694 (QEMU 7.2), prior to CLONE_PIDFD…

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)