gcBgMarkStartWorkers引发无法正常运行的gc并导致nginx无响应
来源:stackoverflow
时间:2024-02-08 19:03:26 489浏览 收藏
欢迎各位小伙伴来到golang学习网,相聚于此都是缘哈哈哈!今天我给大家带来《gcBgMarkStartWorkers引发无法正常运行的gc并导致nginx无响应》,这篇文章主要讲到等等知识,如果你对Golang相关的知识非常感兴趣或者正在自学,都可以关注我,我会持续更新相关文章!当然,有什么建议也欢迎在评论留言提出!一起学习!
$ go version go version go1.19 linux/amd64 $ go env go env go111module="on" goarch="amd64" gobin="" gocache="/root/.cache/go-build" goenv="/root/.config/go/env" goexe="" goexperiment="" goflags="" gohostarch="amd64" gohostos="linux" goinsecure="" gomodcache="/root/go/pkg/mod" gonoproxy="*.qianxin-inc.cn" gonosumdb="*.qianxin-inc.cn" goos="linux" gopath="/root/go" goprivate="*.qianxin-inc.cn" goproxy="https://goproxy.cn,direct" goroot="/root/go" gosumdb="sum.golang.org" gotmpdir="" gotooldir="/root/go/pkg/tool/linux_amd64" govcs="" goversion="go1.19" gccgo="gccgo" goamd64="v1" ar="ar" cc="gcc" cxx="g++" cgo_enabled="1" gomod="/dev/null" 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 -wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build273339992=/tmp/go-build -gno-record-gcc-switches"
我的程序抛出一些错误,但我无法解决。
它是用c编写的,而一些函数是用go编写的。
我使用 `go build -o libtest.so -buildmode=c-shared xxx.go xxx.go;``
执行命令后,得到一个libtest.so
,然后在c程序中通过dlopen
调用它。
我的 c 程序作为 nginx 中的插件运行。
调用go函数后,nginx没有任何响应。我使用gdb对其进行调试,并发现以下回溯:
(gdb) bt #0 runtime.futex () at /usr/local/go/src/runtime/sys_linux_amd64.s:520 #1 0x00007fff23c550f6 in runtime.futexsleep (addr=0xfffffffffffffe00, val=0, ns=140733793710979) at /usr/local/go/src/runtime/os_linux.go:44 #2 0x00007fff23c35667 in runtime.notetsleep_internal (n=0x7fff23dc66e8 <runtime.work+232>, ns=-1) at /usr/local/go/src/runtime/lock_futex.go:183 #3 0x00007fff23c35785 in runtime.notetsleepg (n=0x7fff23dc66e8 <runtime.work+232>, ns=-1) at /usr/local/go/src/runtime/lock_futex.go:237 #4 0x00007fff23c41338 in runtime.gcBgMarkStartWorkers () at /usr/local/go/src/runtime/mgc.go:1126 #5 0x00007fff23c3fd92 in runtime.gcStart (trigger=...) at /usr/local/go/src/runtime/mgc.go:637 #6 0x00007fff23c36e3d in runtime.mallocgc (size=565248, typ=0x7fff23cfd160, needzero=true) at /usr/local/go/src/runtime/malloc.go:1174 #7 0x00007fff23c6dfaa in runtime.growslice (et=, old=..., cap=) at /usr/local/go/src/runtime/slice.go:267 #8 0x00007fff23c918ef in regexp/syntax.(*compiler).inst (c=0xc000044bf8, op=) at /usr/local/go/src/regexp/syntax/compile.go:164 #9 regexp/syntax.(*compiler).rune (c=0xc000044bf8, r=[]int32 = {...}, flags=212) at /usr/local/go/src/regexp/syntax/compile.go:273 #10 0x00007fff23c90f1e in regexp/syntax.(*compiler).compile (c=0xc000044bf8, re=0xc000190000) at /usr/local/go/src/regexp/syntax/compile.go:101 #11 0x00007fff23c8f805 in regexp/syntax.Compile (re=0xc000190000) at /usr/local/go/src/regexp/syntax/compile.go:74 #12 0x00007fff23ca4a9a in regexp.compile (expr=, mode=, longest=false) at /usr/local/go/src/regexp/regexp.go:178 #13 0x00007fff23ca5591 in regexp.Compile (expr="") at /usr/local/go/src/regexp/regexp.go:133 #14 regexp.MustCompile (str="") at /usr/local/go/src/regexp/regexp.go:309 #15 0x00007fff23ca8e0a in main.CheckPostAddress (buf=, bufLen=) at /root/codes/di_rechk/rechk.go:540 #16 0x00007fff23ca9a88 in _cgoexp_67df0785bef2_CheckPostAddress (a=0x7fffffffc740) at _cgo_gotypes.go:162 #17 0x00007fff23c2e21a in runtime.cgocallbackg1 (fn=0x7fff23ca9a60 <_cgoexp_67df0785bef2_CheckPostAddress>, frame=0x7fffffffc740, ctxt=0) at /usr/local/go/src/runtime/cgocall.go:306 #18 0x00007fff23c2dee9 in runtime.cgocallbackg (fn=0x7fff23ca9a60 <_cgoexp_67df0785bef2_CheckPostAddress>, frame=0x7fffffffc740, ctxt=0) at /usr/local/go/src/runtime/cgocall.go:232 #19 0x00007fff23c83791 in runtime.cgocallbackg (fn=0x7fff23ca9a60 <_cgoexp_67df0785bef2_CheckPostAddress>, frame=0x7fffffffc740, ctxt=0) at :1 #20 0x00007fff23c813f3 in runtime.cgocallback () at /usr/local/go/src/runtime/asm_amd64.s:915 #21 0x00007fff23c81601 in runtime.goexit () at /usr/local/go/src/runtime/asm_amd64.s:1581 #22 0x0000000000000000 in ?? () (gdb) info goroutines 17 syscall runtime.notetsleepg 2 waiting runtime.gopark 3 waiting runtime.gopark 4 waiting runtime.gopark 19 runnable runtime.gcBgMarkWorker (gdb) goroutine 17 bt #0 runtime.notetsleepg (n=0x7fff23dc66e8 <runtime.work+232>, ns=-1) at /usr/local/go/src/runtime/lock_futex.go:237 #1 0x00007fff23c41338 in runtime.gcBgMarkStartWorkers () at /usr/local/go/src/runtime/mgc.go:1126 #2 0x00007fff23c3fd92 in runtime.gcStart (trigger=...) at /usr/local/go/src/runtime/mgc.go:637 #3 0x00007fff23c36e3d in runtime.mallocgc (size=565248, typ=0x7fff23cfd160, needzero=true) at /usr/local/go/src/runtime/malloc.go:1174 #4 0x00007fff23c6dfaa in runtime.growslice (et=, old=..., cap=) at /usr/local/go/src/runtime/slice.go:267 #5 0x00007fff23c918ef in regexp/syntax.(*compiler).inst (c=0xc000044bf8, op=) at /usr/local/go/src/regexp/syntax/compile.go:164 #6 regexp/syntax.(*compiler).rune (c=0xc000044bf8, r=[]int32 = {...}, flags=212) at /usr/local/go/src/regexp/syntax/compile.go:273 #7 0x00007fff23c90f1e in regexp/syntax.(*compiler).compile (c=0xc000044bf8, re=0xc00022a000) at /usr/local/go/src/regexp/syntax/compile.go:101 #8 0x00007fff23c8f805 in regexp/syntax.Compile (re=0xc00022a000) at /usr/local/go/src/regexp/syntax/compile.go:74 #9 0x00007fff23ca4a9a in regexp.compile (expr=, mode=, longest=false) at /usr/local/go/src/regexp/regexp.go:178 #10 0x00007fff23ca5591 in regexp.Compile (expr=""") at /usr/local/go/src/regexp/regexp.go:133 #11 regexp.MustCompile (str=""") at /usr/local/go/src/regexp/regexp.go:309 #12 0x00007fff23ca8e0a in main.CheckPostAddress (buf=, bufLen=) at /root/codes/di_rechk/rechk.go:540 #13 0x00007fff23ca9a88 in _cgoexp_67df0785bef2_CheckPostAddress (a=0x7fffffffc740) at _cgo_gotypes.go:162 #14 0x00007fff23c2e21a in runtime.cgocallbackg1 (fn=0x7fff23ca9a60 <_cgoexp_67df0785bef2_CheckPostAddress>, frame=0x7fffffffc740, ctxt=0) at /usr/local/go/src/runtime/cgocall.go:306 #15 0x00007fff23c2dee9 in runtime.cgocallbackg (fn=0x7fff23ca9a60 <_cgoexp_67df0785bef2_CheckPostAddress>, frame=0x7fffffffc740, ctxt=0) at /usr/local/go/src/runtime/cgocall.go:232 #16 0x00007fff23c83791 in runtime.cgocallbackg (fn=0x7fff23ca9a60 <_cgoexp_67df0785bef2_CheckPostAddress>, frame=0x7fffffffc740, ctxt=0) at :1 #17 0x00007fff23c813f3 in runtime.cgocallback () at /usr/local/go/src/runtime/asm_amd64.s:915 #18 0x00007fff23c81601 in runtime.goexit () at /usr/local/go/src/runtime/asm_amd64.s:1581 #19 0x0000000000000000 in ?? () (gdb) goroutine 2 bt #0 runtime.gopark (unlockf=, lock=, reason=, traceEv=, traceskip=) at /usr/local/go/src/runtime/proc.go:367 #1 0x00007fff23c5b86d in runtime.goparkunlock (reason=, traceEv=, traceskip=, lock=) at /usr/local/go/src/runtime/proc.go:372 #2 runtime.forcegchelper () at /usr/local/go/src/runtime/proc.go:306 #3 0x00007fff23c81601 in runtime.goexit () at /usr/local/go/src/runtime/asm_amd64.s:1581 #4 0x0000000000000000 in ?? () (gdb) goroutine 3 bt #0 runtime.gopark (unlockf=, lock=, reason=, traceEv=, traceskip=) at /usr/local/go/src/runtime/proc.go:367 #1 0x00007fff23c48ee8 in runtime.goparkunlock (reason=, traceEv=, traceskip=, lock=) at /usr/local/go/src/runtime/proc.go:372 #2 runtime.bgsweep () at /usr/local/go/src/runtime/mgcsweep.go:163 #3 0x00007fff23c81601 in runtime.goexit () at /usr/local/go/src/runtime/asm_amd64.s:1581 #4 0x0000000000000000 in ?? () (gdb) goroutine 4 bt #0 runtime.gopark (unlockf=, lock=, reason=, traceEv=, traceskip=) at /usr/local/go/src/runtime/proc.go:367 #1 0x00007fff23c46fed in runtime.goparkunlock (reason=, traceEv=, traceskip=, lock=) at /usr/local/go/src/runtime/proc.go:372 #2 runtime.bgscavenge () at /usr/local/go/src/runtime/mgcscavenge.go:265 #3 0x00007fff23c81601 in runtime.goexit () at /usr/local/go/src/runtime/asm_amd64.s:1581 #4 0x0000000000000000 in ?? () (gdb) goroutine 19 bt #0 runtime.gcBgMarkWorker () at /usr/local/go/src/runtime/mgc.go:1166 #1 0x00007fff23c81601 in runtime.goexit () at /usr/local/go/src/runtime/asm_amd64.s:1581 #2 0x0000000000000000 in ?? () (gdb) info threads Id Target Id Frame 1 Thread 0x7ffff7966b80 (LWP 2024707) "nginx" runtime.futex () at /usr/local/go/src/runtime/sys_linux_amd64.s:520 2 Thread 0x7ffef1ffb700 (LWP 2024717) "nginx" 0x00007ffff7a483bf in __GI___clock_nanosleep (clock_id=clock_id@entry=0, flags=flags@entry=0, req=req@entry=0x7ffef1ffae80, rem=rem@entry=0x0) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:78 3 Thread 0x7ffef27fc700 (LWP 2024718) "ZMQbg/Reaper" 0x00007ffff7a8a5ce in epoll_wait (epfd=42, events=events@entry=0x7ffef27fb200, maxevents=maxevents@entry=256, timeout=timeout@entry=-1) at ../sysdeps/unix/sysv/linux/epoll_wait.c:30 4 Thread 0x7ffef2ffd700 (LWP 2024719) "ZMQbg/IO/0" 0x00007ffff7a8a5ce in epoll_wait (epfd=44, events=events@entry=0x7ffef2ffc200, maxevents=maxevents@entry=256, timeout=timeout@entry=-1) at ../sysdeps/unix/sysv/linux/epoll_wait.c:30
我在这里做错了什么?
正确答案
我已经解决了这个问题,我从How to debug C-shared library (written in Go) - it hangs on net call得到了答案,你想知道原因,请访问网站。
我的程序运行在master-worker模型上,问题出现在work进程中。 我在fork子进程之前使用dlopen函数打开so文件,因此子进程没有go运行时线程。
文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《gcBgMarkStartWorkers引发无法正常运行的gc并导致nginx无响应》文章吧,也可关注golang学习网公众号了解相关技术文章。
-
502 收藏
-
502 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
139 收藏
-
204 收藏
-
325 收藏
-
477 收藏
-
486 收藏
-
439 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 507次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习