bgp / stayrtr

RPKI-To-Router server implementation in Go
BSD 3-Clause "New" or "Revised" License
91 stars 13 forks source link

Segfaults when the source HTTP endpoint does not accept connections #67

Closed rfc1036 closed 1 year ago

rfc1036 commented 2 years ago
./_build/bin/stayrtr -cache http://localhost:12345/
ERRO[0000] Error updating: Get "http://localhost:12345/": dial tcp [::1]:12345: connect: connection refused 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x7b0ace]

goroutine 1 [running]:
main.(*state).updateFromNewState(0xc0001b4000)
    github.com/bgp/stayrtr/cmd/stayrtr/stayrtr.go:256 +0x4e
main.main()
    github.com/bgp/stayrtr/cmd/stayrtr/stayrtr.go:587 +0xaf5
[Exit 2]

And also when the input is somehow unexpected:

./_build/bin/stayrtr -cache http://localhost/
INFO[0000] new cache file: Updating sha256 hash  -> 65eaa1d99e3f824a4282a0ef9c752aaeb1ead15d7ec8ef39a11dc5a36f31f90f 
ERRO[0000] Error updating: invalid character '<' looking for beginning of value 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x7b0ace]

goroutine 1 [running]:
main.(*state).updateFromNewState(0xc000206000)
    github.com/bgp/stayrtr/cmd/stayrtr/stayrtr.go:256 +0x4e
main.main()
    github.com/bgp/stayrtr/cmd/stayrtr/stayrtr.go:587 +0xaf5
[Exit 2]

A long-lived daemon should just pause and retry.

job commented 2 years ago

Interesting, I can't reproduce (testing on d7a5d85f4a6b85882246f30e772466dbc37ad460)

feather$ ./stayrtr -cache http://localhost/json
INFO[0000] new cache file: Updating sha256 hash  -> 1901e3ffc81651f9d755f06989c5082e5516a5c211f676b1b89df9d23c5688bf
INFO[0000] New update (4642 uniques, 4642 total prefixes).
INFO[0000] Updated added, new serial 0
INFO[0000] StayRTR Server started (sessionID:17100, refresh:3600, retry:600, expire:7200)
ERRO[0600] Error updating: Get "http://localhost/json": dial tcp [::1]:80: connect: connection refused

Reading https://github.com/bgp/stayrtr/blob/master/cmd/stayrtr/stayrtr.go#L256-L257 I suspect a check is missing related to checktime.

@rfc1036 can you share the JSON you are feeding StayRTR? From which validator is it coming?

rfc1036 commented 2 years ago

There is no JSON: http://localhost:12345/ has no listening daemon and http://localhost/ is the lighttpd default page.

job commented 2 years ago

I can’t repo on OpenBSD. What version are you running? HEAD or a release?

rfc1036 commented 2 years ago

The 0.3.0-2 Debian package, which is built on Debian unstable with no changes from the v0.3.0 upstream tag.

 golang-1.18-go (= 1.18.2-2),
 golang-1.18-src (= 1.18.2-2),
 golang-any (= 2:1.18~3),
 golang-github-alecthomas-units-dev (= 0.0~git20211218.b94a6e3-1),
 golang-github-aws-aws-sdk-go-dev (= 1.43.26-1),
 golang-github-beorn7-perks-dev (= 1.0.1-1),
 golang-github-cespare-xxhash-dev (= 2.1.1-2),
 golang-github-davecgh-go-spew-dev (= 1.1.1-2),
 golang-github-go-kit-log-dev (= 0.2.0-3),
 golang-github-go-logfmt-logfmt-dev (= 0.5.0-2),
 golang-github-jmespath-go-jmespath-dev (= 0.4.0-2),
 golang-github-jpillora-backoff-dev (= 1.0.0-1.1),
 golang-github-json-iterator-go-dev (= 1.1.12-1),
 golang-github-julienschmidt-httprouter-dev (= 1.3.0-1),
 golang-github-modern-go-concurrent-dev (= 1.0.3-1.1),
 golang-github-modern-go-reflect2-dev (= 1.0.2-2),
 golang-github-mwitkow-go-conntrack-dev (= 0.0~git20190716.2f06839-2),
 golang-github-pkg-errors-dev (= 0.9.1-2),
 golang-github-pmezard-go-difflib-dev (= 1.0.0-3),
 golang-github-prometheus-client-golang-dev (= 1.11.1-1),
 golang-github-prometheus-client-model-dev (= 0.2.0-3),
 golang-github-prometheus-common-dev (= 0.32.1-8),
 golang-github-prometheus-procfs-dev (= 0.7.3-2),
 golang-github-sirupsen-logrus-dev (= 1.7.0-2),
 golang-github-stretchr-objx-dev (= 0.3.0-1),
 golang-github-stretchr-testify-dev (= 1.7.0+git20210824.ab6dc32-1),
 golang-go (= 2:1.18~3),
 golang-golang-x-crypto-dev (= 1:0.0~git20220315.3147a52-1),
 golang-golang-x-net-dev (= 1:0.0+git20220225.27dd868+dfsg-1),
 golang-golang-x-oauth2-dev (= 0.0~git20211104.d3ed0bb-1),
 golang-golang-x-sync-dev (= 0.0~git20210220.036812b-1),
 golang-golang-x-sys-dev (= 0.0~git20220422.9388b58-1),
 golang-golang-x-term-dev (= 0.0~git20210615.6886f2d-1),
 golang-golang-x-text-dev (= 0.3.7-1),
 golang-gopkg-alecthomas-kingpin.v2-dev (= 2.2.6-3),
 golang-gopkg-yaml.v2-dev (= 2.4.0-2),
 golang-gopkg-yaml.v3-dev (= 3.0.0~git20210107.496545a-1),
 golang-goprotobuf-dev (= 1.3.4-2+b6),
 golang-logrus-dev (= 1.3.0-1),
 golang-protobuf-extensions-dev (= 1.0.1-1),
job commented 2 years ago

I suspect this changeset fixed this segfault https://github.com/bgp/stayrtr/commit/5878317f6e23a956ae0b83a803d0f52feeb7ebb4

I guess we need to get a release out!

benjojo commented 1 year ago
$ ./dist/stayrtr-0.1-119-gad3ed83-linux-x86_64 -cache http://localhost:12345/
ERRO[0000] Error updating: Get "http://localhost:12345/": dial tcp 127.0.0.1:12345: connect: connection refused 
WARN[0000] Initial sync not complete. Refreshing every 30 seconds 
INFO[0000] StayRTR Server started (sessionID:49746, refresh:3600, retry:600, expire:7200) 

Cannot reproduce on HEAD. I agree a release is due