英文:
Golang: fatal error: unexpected signal during runtime execution
问题
我在执行二进制文件时,随机出现以下错误(有时它可以正常工作):
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x47 pc=0x7f07a019b448]
我运行二进制文件的操作系统版本是:
root@br-operator-b5d68d56c-jbsvf:/# cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.3 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.3 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
Go版本:
go version
go version go1.16.9 linux/amd64
Bazel选项:
go_binary(
name = "app-operator",
embed = [":app-operator_lib"],
gc_linkopts = [
"-linkmode",
"external",
"-extldflags",
"-static",
],
static = "on",
visibility = ["//visibility:public"],
)
我认为这是在以下goroutine中发生的:
goroutine 408 [select]:
net/http.(*Transport).getConn(0x22f49e0, 0xc00080b440, {{}, 0x0, {0x16482cc, 0x4}, {0xc0006d9590, 0x30}, 0x0})
GOROOT/src/net/http/transport.go:1372 +0x5d2
net/http.(*Transport).roundTrip(0x22f49e0, 0xc0005b0400)
GOROOT/src/net/http/transport.go:581 +0x774
net/http.(*Transport).RoundTrip(0x30, 0x1817c80)
GOROOT/src/net/http/roundtrip.go:18 +0x19
net/http.send(0xc0005b0400, {0x1817c80, 0x22f49e0}, {0x15f8740, 0x201, 0x0})
GOROOT/src/net/http/client.go:252 +0x5d8
net/http.(*Client).send(0x2382ea0, 0xc0005b0400, {0x380, 0x0, 0x0})
GOROOT/src/net/http/client.go:176 +0x9b
net/http.(*Client).do(0x2382ea0, 0xc0005b0400)
GOROOT/src/net/http/client.go:725 +0x908
net/http.(*Client).Do(...)
GOROOT/src/net/http/client.go:593
somecompany.com/operators/app-operator/http/client.(*APIClient).callAPI(0xc00078e030, 0xc0005b0400)
operators/app-operator/http/client/client.go:151 +0x12e
somecompany.com/operators/app-operator/http/client.(*BackuprestoreApiService).Poll(0xc0004de148, 0xc00016b8a8)
operators/app-operator/http/client/api_backuprestore.go:216 +0x5bd
somecompany.com/operators/app-operator/controllers.(*BackupReconciler).Poll(0xc0004de120, {0xc00076a4b0, {0xc00021c268, 0xc00016ba38}, 0xc00076a4c0})
operators/app-operator/controllers/backup_controller.go:165 +0x16d
somecompany.com/operators/app-operator/controllers.(*BackupReconciler).Poll(0xc0004de120, {0xc00076a4b0, {0xc00021c268, 0x4f416a}, 0xc00076a4c0})
operators/app-operator/controllers/backup_controller.go:186 +0x396
somecompany.com/operators/app-operator/controllers.(*BackupReconciler).Poll(0xc0004de120, {0xc00076a4b0, {0xc00021c268, 0x4f4226}, 0xc00076a4c0})
operators/app-operator/controllers/backup_controller.go:186 +0x396
somecompany.com/operators/app-operator/controllers.(*BackupReconciler).Backup(0xc0004de120, 0xc0006ab4a0)
operators/app-operator/controllers/backup_controller.go:147 +0x396
somecompany.com/operators/app-operator/controllers.(*BackupReconciler).createBackupHandler(0xc00016bd78, 0x183e758)
operators/app-operator/controllers/backup_controller.go:93 +0x1d
somecompany.com/operators/app-operator/controllers.(*BackupReconciler).Reconcile(0xc0004de120, {0x183e758, 0xc000772d50}, {{{0xc0000596b8, 0x155d9a0}, {0xc0000596b0, 0xc000338100}}})
operators/app-operator/controllers/backup_controller.go:87 +0x1c5
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc0000da320, {0x183e6b0, 0xc0000b4000}, {0x14fda20, 0xc0009a4000})
external/io_k8s_sigs_controller_runtime/pkg/internal/controller/controller.go:298 +0x303
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc0000da320, {0x183e6b0, 0xc0000b4000})
external/io_k8s_sigs_controller_runtime/pkg/internal/controller/controller.go:253 +0x205
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
external/io_k8s_sigs_controller_runtime/pkg/internal/controller/controller.go:214 +0x85
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2
external/io_k8s_sigs_controller_runtime/pkg/internal/controller/controller.go:210 +0x354
英文:
I am randomly getting the following error when I am executing the binary (sometime it works):
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x47 pc=0x7f07a019b448]
Here is the entire stacktrace.
The OS version where I am running the binary:
NAME="Ubuntu"
VERSION="18.04.3 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.3 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
Go version:
go version
go version go1.16.9 linux/amd64
Bazel options:
go_binary(
name = "app-operator",
embed = [":app-operator_lib"],
gc_linkopts = [
"-linkmode",
"external",
"-extldflags",
"-static",
],
static = "on",
visibility = ["//visibility:public"],
)
I think it's happening in this goroutine:
goroutine 408 [select]:
net/http.(*Transport).getConn(0x22f49e0, 0xc00080b440, {{}, 0x0, {0x16482cc, 0x4}, {0xc0006d9590, 0x30}, 0x0})
GOROOT/src/net/http/transport.go:1372 +0x5d2
net/http.(*Transport).roundTrip(0x22f49e0, 0xc0005b0400)
GOROOT/src/net/http/transport.go:581 +0x774
net/http.(*Transport).RoundTrip(0x30, 0x1817c80)
GOROOT/src/net/http/roundtrip.go:18 +0x19
net/http.send(0xc0005b0400, {0x1817c80, 0x22f49e0}, {0x15f8740, 0x201, 0x0})
GOROOT/src/net/http/client.go:252 +0x5d8
net/http.(*Client).send(0x2382ea0, 0xc0005b0400, {0x380, 0x0, 0x0})
GOROOT/src/net/http/client.go:176 +0x9b
net/http.(*Client).do(0x2382ea0, 0xc0005b0400)
GOROOT/src/net/http/client.go:725 +0x908
net/http.(*Client).Do(...)
GOROOT/src/net/http/client.go:593
somecompany.com/operators/app-operator/http/client.(*APIClient).callAPI(0xc00078e030, 0xc0005b0400)
operators/app-operator/http/client/client.go:151 +0x12e
somecompany.com/operators/app-operator/http/client.(*BackuprestoreApiService).Poll(0xc0004de148, 0xc00016b8a8)
operators/app-operator/http/client/api_backuprestore.go:216 +0x5bd
somecompany.com/operators/app-operator/controllers.(*BackupReconciler).Poll(0xc0004de120, {0xc00076a4b0, {0xc00021c268, 0xc00016ba38}, 0xc00076a4c0})
operators/app-operator/controllers/backup_controller.go:165 +0x16d
somecompany.com/operators/app-operator/controllers.(*BackupReconciler).Poll(0xc0004de120, {0xc00076a4b0, {0xc00021c268, 0x4f416a}, 0xc00076a4c0})
operators/app-operator/controllers/backup_controller.go:186 +0x396
somecompany.com/operators/app-operator/controllers.(*BackupReconciler).Poll(0xc0004de120, {0xc00076a4b0, {0xc00021c268, 0x4f4226}, 0xc00076a4c0})
operators/app-operator/controllers/backup_controller.go:186 +0x396
somecompany.com/operators/app-operator/controllers.(*BackupReconciler).Backup(0xc0004de120, 0xc0006ab4a0)
operators/app-operator/controllers/backup_controller.go:147 +0x396
somecompany.com/operators/app-operator/controllers.(*BackupReconciler).createBackupHandler(0xc00016bd78, 0x183e758)
operators/app-operator/controllers/backup_controller.go:93 +0x1d
somecompany.com/operators/app-operator/controllers.(*BackupReconciler).Reconcile(0xc0004de120, {0x183e758, 0xc000772d50}, {{{0xc0000596b8, 0x155d9a0}, {0xc0000596b0, 0xc000338100}}})
operators/app-operator/controllers/backup_controller.go:87 +0x1c5
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc0000da320, {0x183e6b0, 0xc0000b4000}, {0x14fda20, 0xc0009a4000})
external/io_k8s_sigs_controller_runtime/pkg/internal/controller/controller.go:298 +0x303
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc0000da320, {0x183e6b0, 0xc0000b4000})
external/io_k8s_sigs_controller_runtime/pkg/internal/controller/controller.go:253 +0x205
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()
external/io_k8s_sigs_controller_runtime/pkg/internal/controller/controller.go:214 +0x85
created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2
external/io_k8s_sigs_controller_runtime/pkg/internal/controller/controller.go:210 +0x354
答案1
得分: 3
你应该能够从构建中删除gc_linkopts
选项。静态链接glibc
并不是真正支持的,可能会引起问题。
如果你有其他需要静态链接的cgo库,你需要为这些库提供特定的链接器标志。
如果cgo的唯一用途是在Linux上进行名称解析,那么几乎总是可以在构建时不使用cgo,并在需要静态二进制文件而没有可移植的C实现时依赖于本地Go实现。
英文:
You should be able to remove the gc_linkopts
options from the build. Statically linking glibc
is not really supported, and may be causing problems.
If you have other cgo libraries you need to link statically, you will need to provide the linker flags for those libraries specifically.
If the only use of cgo is for name resolution on linux, you can almost always build without cgo and rely on the native Go implementations when a static binary is desired without a portable C implementation.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论