Fatal error: unexpected signal during runtime execution

标签: 问题解决 debug Go 发布于:2022-10-30 20:54:16 编辑于:2022-11-23 12:06:27 浏览量:126

概述

最近几天在写 Gin Template,本地测试都 Okay,然后想部署到服务器上试一下,结果 GitHub OAuth 登录后程序必被杀。

此篇日志用以记录 debug 的经过。

正文

部署用到的 Gin Template 版本:https://github.com/songquanpeng/gin-template/releases/tag/v0.1.2

报错信息(去掉了部分敏感信息):

[GIN] 2022/10/30 - 20:31:39 | 200 |      25.148µs |  | GET      "/oauth/github?code=a6fcd12cfd706e73fd5b"
[GIN] 2022/10/30 - 20:31:39 | 200 |     4.53207ms |  | GET      "/static/css/main.ccda7c20.css"
[GIN] 2022/10/30 - 20:31:39 | 200 |    4.489589ms |  | GET      "/static/js/main.b2afe9d9.js"
[GIN] 2022/10/30 - 20:31:39 | 200 |      90.961µs |  | GET      "/logo.png"
[GIN] 2022/10/30 - 20:31:40 | 200 |      76.285µs |  | GET      "/api/status"
[GIN] 2022/10/30 - 20:31:40 | 200 |     109.047µs |  | GET      "/static/media/icons.38c6d8bab26db77d8c80.woff2"
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x47 pc=0x7f562a48d5ca]

runtime stack:
runtime.throw({0xcf4755, 0x7f5604000d41})
        /opt/hostedtoolcache/go/1.17.13/x64/src/runtime/panic.go:1198 +0x71
runtime.sigpanic()
        /opt/hostedtoolcache/go/1.17.13/x64/src/runtime/signal_unix.go:719 +0x389

goroutine 44 [syscall]:
runtime.cgocall(0xa15670, 0xc000151d90)
        /opt/hostedtoolcache/go/1.17.13/x64/src/runtime/cgocall.go:156 +0x5c fp=0xc000151d68 sp=0xc000151d30 pc=0x40567c
net._C2func_getaddrinfo(0xc0001ad3d0, 0x0, 0xc000484a80, 0xc0002e99d8)
        _cgo_gotypes.go:91 +0x56 fp=0xc000151d90 sp=0xc000151d68 pc=0x52d356
net.cgoLookupIPCNAME.func1({0xc0001ad3d0, 0x0, 0x0}, 0xc000028b88, 0xc000151e40)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/cgo_unix.go:163 +0x9f fp=0xc000151de8 sp=0xc000151d90 pc=0x52ec1f
net.cgoLookupIPCNAME({0xcd6367, 0x3}, {0xc000028b88, 0x5})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/cgo_unix.go:163 +0x16d fp=0xc000151f38 sp=0xc000151de8 pc=0x52e46d
net.cgoIPLookup(0x17c18d0, {0xcd6367, 0xc0002e02c0}, {0xc000028b88, 0xc00031b130})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/cgo_unix.go:220 +0x3b fp=0xc000151fa8 sp=0xc000151f38 pc=0x52ecdb
net.cgoLookupIP·dwrap·25()
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/cgo_unix.go:230 +0x36 fp=0xc000151fe0 sp=0xc000151fa8 pc=0x52f156
runtime.goexit()
        /opt/hostedtoolcache/go/1.17.13/x64/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000151fe8 sp=0xc000151fe0 pc=0x465b41
created by net.cgoLookupIP
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/cgo_unix.go:230 +0x125

goroutine 1 [IO wait]:
internal/poll.runtime_pollWait(0x7f562a576f08, 0x72)
        /opt/hostedtoolcache/go/1.17.13/x64/src/runtime/netpoll.go:303 +0x85
internal/poll.(*pollDesc).wait(0xc000448280, 0xc000038800, 0x0)
        /opt/hostedtoolcache/go/1.17.13/x64/src/internal/poll/fd_poll_runtime.go:84 +0x32
internal/poll.(*pollDesc).waitRead(...)
        /opt/hostedtoolcache/go/1.17.13/x64/src/internal/poll/fd_poll_runtime.go:89
internal/poll.(*FD).Accept(0xc000448280)
        /opt/hostedtoolcache/go/1.17.13/x64/src/internal/poll/fd_unix.go:402 +0x22c
net.(*netFD).accept(0xc000448280)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/fd_unix.go:173 +0x35
net.(*TCPListener).accept(0xc00000f608)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/tcpsock_posix.go:140 +0x28
net.(*TCPListener).Accept(0xc00000f608)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/tcpsock.go:262 +0x3d
net/http.(*Server).Serve(0xc0004400e0, {0x12ded20, 0xc00000f608})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/server.go:3002 +0x394
net/http.(*Server).ListenAndServe(0xc0004400e0)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/server.go:2931 +0x7d
net/http.ListenAndServe(...)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/server.go:3185
github.com/gin-gonic/gin.(*Engine).Run(0xc00036a1a0, {0xc00021ff18, 0x1, 0x1})
        /home/runner/go/pkg/mod/github.com/gin-gonic/gin@v1.7.4/gin.go:336 +0x198
main.main()
        /home/runner/work/gin-template/gin-template/main.go:71 +0x4df

goroutine 5 [select]:
database/sql.(*DB).connectionOpener(0xc000415860, {0x12e3fd8, 0xc00041cec0})
        /opt/hostedtoolcache/go/1.17.13/x64/src/database/sql/sql.go:1196 +0x93
created by database/sql.OpenDB
        /opt/hostedtoolcache/go/1.17.13/x64/src/database/sql/sql.go:794 +0x188

goroutine 6 [sleep]:
time.Sleep(0xdf8475800)
        /opt/hostedtoolcache/go/1.17.13/x64/src/runtime/time.go:193 +0x12e
gin-template/common.(*InMemoryRateLimiter).clearExpiredItems(0x17c1070)
        /home/runner/work/gin-template/gin-template/common/rate-limit.go:30 +0x3f
created by gin-template/common.(*InMemoryRateLimiter).Init
        /home/runner/work/gin-template/gin-template/common/rate-limit.go:21 +0xe7

goroutine 14 [select]:
net/http.(*Transport).getConn(0x17645e0, 0xc000466500, {{}, 0x0, {0xce8cf8, 0x5}, {0xc000028b88, 0x12}, 0x0})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/transport.go:1372 +0x5d2
net/http.(*Transport).roundTrip(0x17645e0, 0xc000468a00)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/transport.go:581 +0x774
net/http.(*Transport).RoundTrip(0xc000468a00, 0x12d4860)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/roundtrip.go:18 +0x19
net/http.send(0xc000468800, {0x12d4860, 0x17645e0}, {0xcb3a00, 0x487e01, 0x17c2640})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/client.go:252 +0x5d8
net/http.(*Client).send(0xc0002ca5a0, 0xc000468800, {0x10, 0xc0004a0a80, 0x17c2640})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/client.go:176 +0x9b
net/http.(*Client).do(0xc0002ca5a0, 0xc000468800)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/client.go:725 +0x908
net/http.(*Client).Do(...)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/client.go:593
gin-template/controller.GitHubOAuth(0xc00041bc00)
        /home/runner/work/gin-template/gin-template/controller/oauth.go:91 +0xd95
github.com/gin-gonic/gin.(*Context).Next(...)
        /home/runner/go/pkg/mod/github.com/gin-gonic/gin@v1.7.4/context.go:165
github.com/gin-contrib/sessions.Sessions.func1(0xc00041bc00)
        /home/runner/go/pkg/mod/github.com/gin-contrib/sessions@v0.0.5/sessions.go:54 +0x18d
github.com/gin-gonic/gin.(*Context).Next(...)
        /home/runner/go/pkg/mod/github.com/gin-gonic/gin@v1.7.4/context.go:165
github.com/gin-gonic/gin.CustomRecoveryWithWriter.func1(0xc00041bc00)
        /home/runner/go/pkg/mod/github.com/gin-gonic/gin@v1.7.4/recovery.go:99 +0x82
github.com/gin-gonic/gin.(*Context).Next(...)
        /home/runner/go/pkg/mod/github.com/gin-gonic/gin@v1.7.4/context.go:165
github.com/gin-gonic/gin.LoggerWithConfig.func1(0xc00041bc00)
        /home/runner/go/pkg/mod/github.com/gin-gonic/gin@v1.7.4/logger.go:241 +0xe7
github.com/gin-gonic/gin.(*Context).Next(...)
        /home/runner/go/pkg/mod/github.com/gin-gonic/gin@v1.7.4/context.go:165
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc00036a1a0, 0xc00041bc00)
        /home/runner/go/pkg/mod/github.com/gin-gonic/gin@v1.7.4/gin.go:489 +0x63e
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc00036a1a0, {0x12def30, 0xc000440380}, 0xc000138300)
        /home/runner/go/pkg/mod/github.com/gin-gonic/gin@v1.7.4/gin.go:445 +0x1c5
net/http.serverHandler.ServeHTTP({0xc0002ca300}, {0x12def30, 0xc000440380}, 0xc000138300)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/server.go:2879 +0x43b
net/http.(*conn).serve(0xc0003f81e0, {0x12e4080, 0xc000433110})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/server.go:1930 +0xb08
created by net/http.(*Server).Serve
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/server.go:3034 +0x4e8

goroutine 40 [IO wait]:
internal/poll.runtime_pollWait(0x7f562a576e18, 0x72)
        /opt/hostedtoolcache/go/1.17.13/x64/src/runtime/netpoll.go:303 +0x85
internal/poll.(*pollDesc).wait(0xc000136300, 0xc000465000, 0x0)
        /opt/hostedtoolcache/go/1.17.13/x64/src/internal/poll/fd_poll_runtime.go:84 +0x32
internal/poll.(*pollDesc).waitRead(...)
        /opt/hostedtoolcache/go/1.17.13/x64/src/internal/poll/fd_poll_runtime.go:89
internal/poll.(*FD).Read(0xc000136300, {0xc000465000, 0xe64, 0xe64})
        /opt/hostedtoolcache/go/1.17.13/x64/src/internal/poll/fd_unix.go:167 +0x25a
net.(*netFD).Read(0xc000136300, {0xc000465000, 0x8f4, 0xc000392000})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/fd_posix.go:56 +0x29
net.(*conn).Read(0xc0000ae088, {0xc000465000, 0x5f0779, 0xc0006977f8})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/net.go:183 +0x45
crypto/tls.(*atLeastReader).Read(0xc000278258, {0xc000465000, 0x0, 0x40bc8d})
        /opt/hostedtoolcache/go/1.17.13/x64/src/crypto/tls/conn.go:778 +0x3d
bytes.(*Buffer).ReadFrom(0xc000362278, {0x12d3d00, 0xc000278258})
        /opt/hostedtoolcache/go/1.17.13/x64/src/bytes/buffer.go:204 +0x98
crypto/tls.(*Conn).readFromUntil(0xc000362000, {0x12d47a0, 0xc0000ae088}, 0xc0006978b8)
        /opt/hostedtoolcache/go/1.17.13/x64/src/crypto/tls/conn.go:800 +0xe5
crypto/tls.(*Conn).readRecordOrCCS(0xc000362000, 0x0)
        /opt/hostedtoolcache/go/1.17.13/x64/src/crypto/tls/conn.go:607 +0x112
crypto/tls.(*Conn).readRecord(...)
        /opt/hostedtoolcache/go/1.17.13/x64/src/crypto/tls/conn.go:575
crypto/tls.(*Conn).Read(0xc000362000, {0xc00045f000, 0x1000, 0xc00036ab60})
        /opt/hostedtoolcache/go/1.17.13/x64/src/crypto/tls/conn.go:1278 +0x16f
bufio.(*Reader).Read(0xc0000710e0, {0xc0004402d8, 0x9, 0xc0000b07e0})
        /opt/hostedtoolcache/go/1.17.13/x64/src/bufio/bufio.go:227 +0x1b4
io.ReadAtLeast({0x12d3ba0, 0xc0000710e0}, {0xc0004402d8, 0x9, 0x9}, 0x9)
        /opt/hostedtoolcache/go/1.17.13/x64/src/io/io.go:328 +0x9a
io.ReadFull(...)
        /opt/hostedtoolcache/go/1.17.13/x64/src/io/io.go:347
net/http.http2readFrameHeader({0xc0004402d8, 0x9, 0xc0004847e0}, {0x12d3ba0, 0xc0000710e0})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/h2_bundle.go:1555 +0x6e
net/http.(*http2Framer).ReadFrame(0xc0004402a0)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/h2_bundle.go:1813 +0x95
net/http.(*http2clientConnReadLoop).run(0xc000697f98)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/h2_bundle.go:8608 +0x130
net/http.(*http2ClientConn).readLoop(0xc000106780)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/h2_bundle.go:8531 +0x6f
created by net/http.(*http2Transport).newClientConn
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/h2_bundle.go:7325 +0xb85

goroutine 15 [IO wait]:
internal/poll.runtime_pollWait(0x7f562a576d28, 0x72)
        /opt/hostedtoolcache/go/1.17.13/x64/src/runtime/netpoll.go:303 +0x85
internal/poll.(*pollDesc).wait(0xc000136100, 0xc0002ca311, 0x0)
        /opt/hostedtoolcache/go/1.17.13/x64/src/internal/poll/fd_poll_runtime.go:84 +0x32
internal/poll.(*pollDesc).waitRead(...)
        /opt/hostedtoolcache/go/1.17.13/x64/src/internal/poll/fd_poll_runtime.go:89
internal/poll.(*FD).Read(0xc000136100, {0xc0002ca311, 0x1, 0x1})
        /opt/hostedtoolcache/go/1.17.13/x64/src/internal/poll/fd_unix.go:167 +0x25a
net.(*netFD).Read(0xc000136100, {0xc0002ca311, 0xc313c0, 0xc000151748})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/fd_posix.go:56 +0x29
net.(*conn).Read(0xc0000ae028, {0xc0002ca311, 0xc000299190, 0xc0000c20a0})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/net.go:183 +0x45
net/http.(*connReader).backgroundRead(0xc0002ca300)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/server.go:672 +0x3f
created by net/http.(*connReader).startBackgroundRead
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/server.go:668 +0xcf

goroutine 42 [select]:
net.(*Resolver).lookupIPAddr(0x17c18c0, {0x12e4048, 0xc000071260}, {0xcd6367, 0xc000036000}, {0xc000028b88, 0xe})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/lookup.go:302 +0x5c7
net.(*Resolver).internetAddrList(0x12e4048, {0x12e4048, 0xc000071260}, {0xcd6367, 0x3}, {0xc000028b88, 0x12})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/ipsock.go:288 +0x67a
net.(*Resolver).resolveAddrList(0x17fa340, {0x12e4048, 0xc000071260}, {0xcd696b, 0x4}, {0xcd6367, 0x5}, {0xc000028b88, 0x12}, {0x0, ...})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/dial.go:221 +0x41b
net.(*Dialer).DialContext(0xc0000b0240, {0x12e4048, 0xc000071260}, {0xcd6367, 0x7f5654259f30}, {0xc000028b88, 0x118})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/dial.go:406 +0x448
net/http.(*Transport).dial(0xc000071260, {0x12e4048, 0xc000071260}, {0xcd6367, 0xc0001068b8}, {0xc000028b88, 0x6d510e})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/transport.go:1166 +0xda
net/http.(*Transport).dialConn(0x17645e0, {0x12e4048, 0xc000071260}, {{}, 0x0, {0xce8cf8, 0x5}, {0xc000028b88, 0x12}, 0x0})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/transport.go:1604 +0x845
net/http.(*Transport).dialConnFor(0xe, 0xc00031b290)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/transport.go:1446 +0xb0
created by net/http.(*Transport).queueForDial
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/http/transport.go:1415 +0x3d7

goroutine 43 [select]:
net.cgoLookupIP({0x12e3fd8, 0xc000466940}, {0xcd6367, 0xe}, {0xc000028b88, 0xc000106780})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/cgo_unix.go:231 +0x1b7
net.(*Resolver).lookupIP(0x17c18c0, {0x12e3fd8, 0xc000466940}, {0xcd6367, 0x3}, {0xc000028b88, 0xe})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/lookup_unix.go:97 +0x128
net.glob..func1({0x12e3fd8, 0xc000466940}, 0x0, {0xcd6367, 0x0}, {0xc000028b88, 0x6bf750})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/hook.go:23 +0x3d
net.(*Resolver).lookupIPAddr.func1()
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/lookup.go:296 +0x9f
internal/singleflight.(*Group).doCall(0x17c18d0, 0xc0003f6320, {0xc000028c48, 0x12}, 0xc00031b290)
        /opt/hostedtoolcache/go/1.17.13/x64/src/internal/singleflight/singleflight.go:95 +0x3b
created by internal/singleflight.(*Group).DoChan
        /opt/hostedtoolcache/go/1.17.13/x64/src/internal/singleflight/singleflight.go:88 +0x2f1    

注意到上面日志中正常打印了 OAuth 请求的日志,实际上检查前端控制台报错信息发现得到的服务器回复是 502,是 Nginx 发的, 说明程序此时就已经挂掉了。

服务器系统版本:5.4.0-96-generic

WSL 系统版本(本地 WSL 测试没问题):5.10.16.3-microsoft-standard-WSL2

用以打包程序的 GitHub Actions(相关片段):

runs-on: ubuntu-latest
uses: actions/setup-go@v3
go mod download
go build -ldflags "-s -w -extldflags '-static' -X 'gin-template/common.Version=$(git describe --tags)'" -o gin-template

查了一下,系统是 ubuntu-20.04,Go 的版本是去看 actions/setup-go 还是不确定,之后想到 GitHub Actions 的日志 可能有,查了一下是:go version go1.17.13 linux/amd64

看程序版本的的时候我顺便看了下打包日志,发现了可疑的地方:

# gin-template
/usr/bin/ld: /tmp/go-link-159369177/000028.o: in function `unixDlOpen':
/home/runner/go/pkg/mod/github.com/mattn/go-sqlite3@v2.0.3+incompatible/sqlite3-binding.c:39689: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-159369177/000004.o: in function `_cgo_3c1cec0c9a4e_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:58: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

这个 getaddrinfo 是不是有点眼熟?没错,上面一大串的报错日志里就有这个函数,而且报错信息里确实好多 cgo 相关的:

goroutine 44 [syscall]:
runtime.cgocall(0xa15670, 0xc000151d90)
        /opt/hostedtoolcache/go/1.17.13/x64/src/runtime/cgocall.go:156 +0x5c fp=0xc000151d68 sp=0xc000151d30 pc=0x40567c
net._C2func_getaddrinfo(0xc0001ad3d0, 0x0, 0xc000484a80, 0xc0002e99d8)
        _cgo_gotypes.go:91 +0x56 fp=0xc000151d90 sp=0xc000151d68 pc=0x52d356
net.cgoLookupIPCNAME.func1({0xc0001ad3d0, 0x0, 0x0}, 0xc000028b88, 0xc000151e40)
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/cgo_unix.go:163 +0x9f fp=0xc000151de8 sp=0xc000151d90 pc=0x52ec1f
net.cgoLookupIPCNAME({0xcd6367, 0x3}, {0xc000028b88, 0x5})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/cgo_unix.go:163 +0x16d fp=0xc000151f38 sp=0xc000151de8 pc=0x52e46d
net.cgoIPLookup(0x17c18d0, {0xcd6367, 0xc0002e02c0}, {0xc000028b88, 0xc00031b130})
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/cgo_unix.go:220 +0x3b fp=0xc000151fa8 sp=0xc000151f38 pc=0x52ecdb
net.cgoLookupIP·dwrap·25()
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/cgo_unix.go:230 +0x36 fp=0xc000151fe0 sp=0xc000151fa8 pc=0x52f156
runtime.goexit()
        /opt/hostedtoolcache/go/1.17.13/x64/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000151fe8 sp=0xc000151fe0 pc=0x465b41
created by net.cgoLookupIP
        /opt/hostedtoolcache/go/1.17.13/x64/src/net/cgo_unix.go:230 +0x125

所以问题大概率出在静态链接的问题上。

检查打包的命令:go build -ldflags "-s -w -extldflags '-static' -X 'gin-template/common.Version=$(git describe --tags)'" -o gin-template

其中: --ldflags sets the flags that are passed to 'go tool link'

  1. -s:turns off DWARF debugging information
  2. -w:turns off generation of the Go symbol table
  3. -X 'gin-template/common.Version=$(git describe --tags)'":用于把版本信息打包进可执行文件
  4. -extldflags set space-separated flags to pass to the external linker,这里因为我们用到了 CGO,所以会用到 GCC 和 ld
    • -static:Do not link against shared libraries. This is only meaningful on platforms for which shared libraries are supported.

这里的 -ldflags "-s -w -extldflags '-static' 都是为了减少生成文件的体积。

去掉 -extldflags '-static' 后打包,程序反而小了 1.3MB,笑死。 上线测试,报错超时,不过这就是因为国内的服务器被干扰间歇性无法与 GitHub 服务器建立连接的问题了。

只能等他不抽风的时候再测试了,佛了。


好了等了一小会儿,测试通过了。

其实还有一个遗留问题,我这里用 CGO 是因为 SQLite,但是 getaddrinfo 看上去是网络相关的,有关联吗? 先不管了,跑步去咯。

总结

  1. 遇到问题,首先尝试本地复现,复现成功,则方便本地调试,复现不成功,则检查环境差异。
  2. 仔细检查日志,本次 debug 过程中的关键信息 getaddrinfo 就是因为我多看了日志几眼留下了印象。
  3. 就算是 Go 这种打包成单个可执行文件的还是有可能遇到环境问题。
  4. 查到命令后在用之前要好好调查一下各个参数的含义,不能知其然而不知其所以然。

参考

  1. https://stackoverflow.com/questions/22267189/what-does-the-w-flag-mean-when-passed-in-via-the-ldflags-option-to-the-go-comman
  2. https://stackoverflow.com/questions/37630274/what-do-these-go-build-flags-mean-netgo-extldflags-lm-lstdc-static
  3. https://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html
  4. https://stackoverflow.com/questions/69773478/golang-fatal-error-unexpected-signal-during-runtime-execution

未经允许,禁止转载,本文源站链接:https://iamazing.cn/