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

Is CGO Required for gobetween on Linux #125

Closed
TechIsCool opened this issue Jan 26, 2018 · 3 comments
Closed

Is CGO Required for gobetween on Linux #125

TechIsCool opened this issue Jan 26, 2018 · 3 comments
Assignees
Milestone

Comments

@TechIsCool
Copy link
Contributor

TechIsCool commented Jan 26, 2018

I have been trying to use gobetween on windows and linux. Windows is working great but my first try at getting linux working has ended in failure.

Compiled on CentOS 7.4

sudo yum -y install go
sudo yum -y group install "Development Tools"
sudo yum -y install glibc-static libstdc++-static
go version
# go version go1.8.3 linux/amd64
gcc --version
# gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)
ldd --version
# ldd (GNU libc) 2.17

cd ~/
git clone https://github.com/TechIsCool/gobetween
cd gobetween
git checkout fallback-address
make dist

and then grabbed the version from there and ran it.

The Error is listed bellow.

Jan 26 20:31:32 testsrv.local gobetween[31991]: gobetween v0.5.0.1
Jan 26 20:31:32 testsrv.local gobetween[31991]: 2018-01-26 20:31:32 [INFO ] (api): Starting up API
Jan 26 20:31:32 testsrv.local gobetween[31991]: 2018-01-26 20:31:32 [INFO ] (api): Starting HTTP server :8888
Jan 26 20:31:32 testsrv.local gobetween[31991]: 2018-01-26 20:31:32 [INFO ] (manager): Initializing...
Jan 26 20:31:32 testsrv.local gobetween[31991]: 2018-01-26 20:31:32 [INFO ] (server): Creating 'maxscale': 127.0.0.1:3306 weight consul ping
Jan 26 20:31:32 testsrv.local gobetween[31991]: 2018-01-26 20:31:32 [INFO ] (scheduler): Starting scheduler
Jan 26 20:31:32 testsrv.local gobetween[31991]: 2018-01-26 20:31:32 [INFO ] (manager): Initialized
Jan 26 20:31:32 testsrv.local gobetween[31991]: 2018-01-26 20:31:32 [INFO ] (consulFetch): Fetching {consul keeplast 30s 5s <nil> <nil> <nil> <nil> <nil> <nil> 0xc4201a1cc0 <nil>}
Jan 26 20:32:02 testsrv.local gobetween[31991]: 2018-01-26 20:32:02 [INFO ] (consulFetch): Fetching {consul keeplast 30s 5s <nil> <nil> <nil> <nil> <nil> <nil> 0xc4201a1cc0 <nil>}
Jan 26 20:32:02 testsrv.local gobetween[31991]: fatal error: unexpected signal during runtime execution
Jan 26 20:32:02 testsrv.local gobetween[31991]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x47 pc=0x7f259edee60d]
Jan 26 20:32:02 testsrv.local gobetween[31991]: runtime stack:
Jan 26 20:32:02 testsrv.local gobetween[31991]: runtime.throw(0xee64e2, 0x2a)
Jan 26 20:32:02 testsrv.local gobetween[31991]: /usr/lib/golang/src/runtime/panic.go:596 +0x95
Jan 26 20:32:02 testsrv.local gobetween[31991]: runtime.sigpanic()
Jan 26 20:32:02 testsrv.local gobetween[31991]: /usr/lib/golang/src/runtime/signal_unix.go:274 +0x2db
Jan 26 20:32:02 testsrv.local gobetween[31991]: goroutine 101 [syscall, locked to thread]:
Jan 26 20:32:02 testsrv.local gobetween[31991]: runtime.cgocall(0xc06800, 0xc42026eab0, 0xee5525)
Jan 26 20:32:02 testsrv.local gobetween[31991]: /usr/lib/golang/src/runtime/cgocall.go:131 +0xe2 fp=0xc42026ea70 sp=0xc42026ea30
Jan 26 20:32:02 testsrv.local gobetween[31991]: net._C2func_getaddrinfo(0x7f25a00008c0, 0x0, 0xc42027c0f0, 0xc42000e318, 0x0, 0x0, 0x0)
Jan 26 20:32:02 testsrv.local gobetween[31991]: net/_obj/_cgo_gotypes.go:86 +0x68 fp=0xc42026eab0 sp=0xc42026ea70
Jan 26 20:32:02 testsrv.local gobetween[31991]: net.cgoLookupIPCNAME.func2(0x7f25a00008c0, 0x0, 0xc42027c0f0, 0xc42000e318, 0x0, 0x30, 0xc420257500)
Jan 26 20:32:02 testsrv.local gobetween[31991]: /usr/lib/golang/src/net/cgo_unix.go:151 +0x171 fp=0xc42026eb10 sp=0xc42026eab0
Jan 26 20:32:02 testsrv.local gobetween[31991]: net.cgoLookupIPCNAME(0xc42025cd30, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
Jan 26 20:32:02 testsrv.local gobetween[31991]: /usr/lib/golang/src/net/cgo_unix.go:151 +0x1bd fp=0xc42026ec10 sp=0xc42026eb10
Jan 26 20:32:02 testsrv.local systemd[1]: gobetween.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Jan 26 20:32:02 testsrv.local systemd[1]: Unit gobetween.service entered failed state.
Jan 26 20:32:02 testsrv.local systemd[1]: gobetween.service failed.
Jan 26 20:32:03 testsrv.local systemd[1]: gobetween.service holdoff time over, scheduling restart.
Jan 26 20:32:03 testsrv.local systemd[1]: Started gobetween.
Jan 26 20:32:03 testsrv.local systemd[1]: Starting gobetween...
Jan 26 20:32:03 testsrv.local gobetween[31999]: gobetween v0.5.0.1

Currently I think I worked around this problem by not building with the CGO_ENABLED=1 flag

make

running from the bin folder it seems stable. But my question is is there a specific reason its setup to run with cgo on linux. When looking at the make file it seems like its required. But could be a hold over from earlier versions of go.

@TechIsCool
Copy link
Contributor Author

TechIsCool commented Jan 26, 2018

After reading up some more on this it looks like the binary file I have build is not statically linked.

file dist/gobetween
# gobetween: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=e181fa0e51f7b4c534999a59cc30ec44d059855a, stripped
file bin/gobetween
# gobetween: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=9b716b997353e6bd22ad77fabd7ac86b28bab0c4, not stripped

If I try forcing CGO_ENABLED=0 then lxc/lxd starts having problems.

Looking over what causes this it seems to be a component that breaks.

golang/go#17384

Uppon further review of the stacktrace it looks like the code is bailing out on a DNS request in the net subsection. Since net supports both glibc linking for DNS and golang linking.
I have disabled CGO_ENABLED=0 and added the flag -a -tags netgo to make build-static and will see if that resolves the issue.

Answers to why this exists can be seen here
prometheus/alertmanager#304

@jamesjmurtagh
Copy link

I can confirm that adding -a -tags netgo to make build-static resolved the issue for me. Thanks, @TechIsCool !

@illarion illarion self-assigned this Apr 4, 2019
@illarion illarion added this to the 0.7.0 milestone Apr 4, 2019
@illarion
Copy link
Collaborator

illarion commented Apr 5, 2019

Fixed. Thank you @jamesjmurtagh @TechIsCool

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

3 participants