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

简单的Gin示范代码无法在Milkv-duo 256的Buildroot镜像上运行 #907

Open
walker2048 opened this issue Feb 26, 2024 · 7 comments

Comments

@walker2048
Copy link

系统信息

[root@milkv-duo]~# cat /etc/os-release 
NAME=Buildroot
VERSION=20231230-2325
ID=buildroot
VERSION_ID=2021.05
PRETTY_NAME="Buildroot 2021.05"

golang代码如下(也尝试了Golang的HTTP Server,Socket等等简单案例代码,都是和下面报错的信息一样,runtime: epollcreate failed with 38),只有不使用网络的Helloworld,打印等等案例可以正常执行。

package main

import "github.com/gin-gonic/gin"

func main() {
	r := gin.Default()
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "pong",
		})
	})
	r.Run() // 监听并在 0.0.0.0:8080 上启动服务
}

使用的交叉编译命令(相同命令编译的Helloworld程序可以在milkv上运行)
GOARCH=riscv64 go build -o ping ping.go

使用ld库检查可执行程序ping的依赖情况,提示无依赖需求
[root@milkv-duo]~# /lib64/ld-musl-riscv64v0p7_xthead.so.1 --list ping
/lib64/ld-musl-riscv64v0p7_xthead.so.1: ping: Not a valid dynamic program

以下是ping程序的运行报错信息

[root@milkv-duo]~# ./ping
runtime: epollcreate failed with 38
fatal error: runtime: netpollinit failed

goroutine 1 [running, locked to thread]:
runtime.throw({0x41857b?, 0xa9cb8?})
        /mnt/MyNAS/walker/.bin/go/src/runtime/panic.go:1047 +0x44 fp=0x3fa429f5e8 sp=0x3fa429f5c0 pc=0x4347c
runtime.netpollinit()
        /mnt/MyNAS/walker/.bin/go/src/runtime/netpoll_epoll.go:28 +0x1b4 fp=0x3fa429f658 sp=0x3fa429f5e8 pc=0x3f4a4
runtime.netpollGenericInit()
        /mnt/MyNAS/walker/.bin/go/src/runtime/netpoll.go:197 +0x64 fp=0x3fa429f668 sp=0x3fa429f658 pc=0x3e9bc
internal/poll.runtime_pollServerInit()
        /mnt/MyNAS/walker/.bin/go/src/runtime/netpoll.go:189 +0x20 fp=0x3fa429f670 sp=0x3fa429f668 pc=0x6d940
sync.(*Once).doSlow(0xf7f84?, 0xf7eb4?)
        /mnt/MyNAS/walker/.bin/go/src/sync/once.go:74 +0xf4 fp=0x3fa429f6c0 sp=0x3fa429f670 pc=0x7b9b4
sync.(*Once).Do(...)
        /mnt/MyNAS/walker/.bin/go/src/sync/once.go:65
internal/poll.(*pollDesc).init(0x3fa40faaf8, 0x3fa40faae0?)
        /mnt/MyNAS/walker/.bin/go/src/internal/poll/fd_poll_runtime.go:39 +0x64 fp=0x3fa429f6d8 sp=0x3fa429f6c0 pc=0xf2094
internal/poll.(*FD).Init(0x3fa40faae0, {0x402670?, 0x80000?}, 0x9c?)
        /mnt/MyNAS/walker/.bin/go/src/internal/poll/fd_unix.go:63 +0xa0 fp=0x3fa429f6f0 sp=0x3fa429f6d8 pc=0xf29e8
os.newFile(0x3, {0x3fa43b0810, 0xa}, 0x1)
        /mnt/MyNAS/walker/.bin/go/src/os/file_unix.go:190 +0x1bc fp=0x3fa429f728 sp=0x3fa429f6f0 pc=0xf7fe4
os.openFileNolog({0x3fa43b0810, 0xa}, 0x0, 0x0)
        /mnt/MyNAS/walker/.bin/go/src/os/file_unix.go:250 +0x19c fp=0x3fa429f768 sp=0x3fa429f728 pc=0xf81fc
os.OpenFile({0x3fa43b0810, 0xa}, 0x0, 0x0?)
        /mnt/MyNAS/walker/.bin/go/src/os/file.go:326 +0x64 fp=0x3fa429f798 sp=0x3fa429f768 pc=0xf7704
os.Open(...)
        /mnt/MyNAS/walker/.bin/go/src/os/file.go:306
google.golang.org/protobuf/internal/detrand.binaryHash()
        /mnt/MyNAS/walker/go/pkg/mod/google.golang.org/protobuf@v1.32.0/internal/detrand/rand.go:46 +0x48 fp=0x3fa429f858 sp=0x3fa429f798 pc=0x310690
google.golang.org/protobuf/internal/detrand.init()
        /mnt/MyNAS/walker/go/pkg/mod/google.golang.org/protobuf@v1.32.0/internal/detrand/rand.go:38 +0x20 fp=0x3fa429f860 sp=0x3fa429f858 pc=0x310910
runtime.doInit(0x704120)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:6506 +0x12c fp=0x3fa429f990 sp=0x3fa429f860 pc=0x535bc
runtime.doInit(0x704160)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:6483 +0x78 fp=0x3fa429fac0 sp=0x3fa429f990 pc=0x53508
runtime.doInit(0x707de0)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:6483 +0x78 fp=0x3fa429fbf0 sp=0x3fa429fac0 pc=0x53508
runtime.doInit(0x708dc0)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:6483 +0x78 fp=0x3fa429fd20 sp=0x3fa429fbf0 pc=0x53508
runtime.doInit(0x70b100)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:6483 +0x78 fp=0x3fa429fe50 sp=0x3fa429fd20 pc=0x53508
runtime.doInit(0x701fe0)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:6483 +0x78 fp=0x3fa429ff80 sp=0x3fa429fe50 pc=0x53508
runtime.main()
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:233 +0x1d0 fp=0x3fa429ffd8 sp=0x3fa429ff80 pc=0x45ab0
runtime.goexit()
        /mnt/MyNAS/walker/.bin/go/src/runtime/asm_riscv64.s:512 +0x4 fp=0x3fa429ffd8 sp=0x3fa429ffd8 pc=0x7281c

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:381 +0x110 fp=0x3fa403afb0 sp=0x3fa403af98 pc=0x45f68
runtime.goparkunlock(...)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:387
runtime.forcegchelper()
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:305 +0xc8 fp=0x3fa403afd8 sp=0x3fa403afb0 pc=0x45da0runtime.goexit()
        /mnt/MyNAS/walker/.bin/go/src/runtime/asm_riscv64.s:512 +0x4 fp=0x3fa403afd8 sp=0x3fa403afd8 pc=0x7281c
created by runtime.init.5
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:293 +0x28

goroutine 3 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:381 +0x110 fp=0x3fa403b788 sp=0x3fa403b770 pc=0x45f68
runtime.goparkunlock(...)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:387
runtime.bgsweep(0x0?)
        /mnt/MyNAS/walker/.bin/go/src/runtime/mgcsweep.go:278 +0xa8 fp=0x3fa403b7c8 sp=0x3fa403b788 pc=0x32228
runtime.gcenable.func1()
        /mnt/MyNAS/walker/.bin/go/src/runtime/mgc.go:178 +0x2c fp=0x3fa403b7d8 sp=0x3fa403b7c8 pc=0x26f44
runtime.goexit()
        /mnt/MyNAS/walker/.bin/go/src/runtime/asm_riscv64.s:512 +0x4 fp=0x3fa403b7d8 sp=0x3fa403b7d8 pc=0x7281c
created by runtime.gcenable
        /mnt/MyNAS/walker/.bin/go/src/runtime/mgc.go:178 +0x70

goroutine 4 [GC scavenge wait]:
runtime.gopark(0x3fa4050000?, 0x4a23b8?, 0x0?, 0x0?, 0x0?)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:381 +0x110 fp=0x3fa403bf80 sp=0x3fa403bf68 pc=0x45f68
runtime.goparkunlock(...)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:387
runtime.(*scavengerState).park(0x757d40)
        /mnt/MyNAS/walker/.bin/go/src/runtime/mgcscavenge.go:400 +0x68 fp=0x3fa403bfa8 sp=0x3fa403bf80 pc=0x30100
runtime.bgscavenge(0x0?)
        /mnt/MyNAS/walker/.bin/go/src/runtime/mgcscavenge.go:628 +0x50 fp=0x3fa403bfc8 sp=0x3fa403bfa8 pc=0x30658
runtime.gcenable.func2()
        /mnt/MyNAS/walker/.bin/go/src/runtime/mgc.go:179 +0x2c fp=0x3fa403bfd8 sp=0x3fa403bfc8 pc=0x26ee4
runtime.goexit()
        /mnt/MyNAS/walker/.bin/go/src/runtime/asm_riscv64.s:512 +0x4 fp=0x3fa403bfd8 sp=0x3fa403bfd8 pc=0x7281c
created by runtime.gcenable
        /mnt/MyNAS/walker/.bin/go/src/runtime/mgc.go:179 +0xb0

goroutine 5 [finalizer wait]:
runtime.gopark(0x3fa403a590?, 0x11?, 0xd0?, 0x4d?, 0x3eb760?)
        /mnt/MyNAS/walker/.bin/go/src/runtime/proc.go:381 +0x110 fp=0x3fa403a5a8 sp=0x3fa403a590 pc=0x45f68
runtime.runfinq()
        /mnt/MyNAS/walker/.bin/go/src/runtime/mfinal.go:193 +0x100 fp=0x3fa403a7d8 sp=0x3fa403a5a8 pc=0x26050
runtime.goexit()
        /mnt/MyNAS/walker/.bin/go/src/runtime/asm_riscv64.s:512 +0x4 fp=0x3fa403a7d8 sp=0x3fa403a7d8 pc=0x7281c
created by runtime.createfing
        /mnt/MyNAS/walker/.bin/go/src/runtime/mfinal.go:163 +0x64
@xen0n
Copy link
Contributor

xen0n commented Feb 26, 2024

What about your Go environment -- go version and go env output would be necessary for us to help.

@dramforever
Copy link

看起来 buildroot 的内核没有开 CONFIG_EPOLL=y,需要修改内核配置文件然后重新编译内核

@FIFCC
Copy link
Contributor

FIFCC commented Feb 26, 2024

你好,麻烦提供一下以下内容以供于复现:
1、镜像链接
2、操作步骤以及相关代码
3、go的版本以及环境

是网络轮询初始化失败以及epoll调用失败的问题,建议查看网络相关系统日志以及修改内核配置文件后重试

@walker2048
Copy link
Author

What about your Go environment -- go version and go env output would be necessary for us to help.

我的环境如下:
go version
go version go1.20.2 linux/amd64
go env

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/mnt/MyNAS/walker/.cache/go-build"
GOENV="/mnt/MyNAS/walker/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/mnt/MyNAS/walker/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/mnt/MyNAS/walker/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/mnt/MyNAS/walker/.bin/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/mnt/MyNAS/walker/.bin/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4163582187=/tmp/go-build -gno-record-gcc-switches"

@mengzhuo
Copy link

Linux 应该是需要EPOLL的,但是wiki里没有描述,对应CL是
https://go-review.googlesource.com/c/wiki/+/566875

@walker2048
Copy link
Author

walker2048 commented Feb 26, 2024

感谢各位大佬,内核配置开启了CONFIG_EPOLL=y和CONFIG_FUTEX=y这两个选项后,Golang的网络功能已经可以正常使用了。

@mengzhuo
Copy link

Go wiki已更新,Linux 除了版本 最低要求是FUTEX + EPOLL,应该可以关闭这个issue了

https://go.dev/wiki/MinimumRequirements#linuxlinux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants