thisisdevelopment / helium-route-updater

Automatically adds / removes euis from your helium routes based on updates from your LNS
MIT License
6 stars 2 forks source link

Crash on Invalid Data #3

Closed kent-williams closed 1 year ago

kent-williams commented 1 year ago

I have found the service to crash if any invalid API requests are made. For instance, the below crash was after attempting device creation via the Chirpstack API with a missing dev_eui. It seems like we might need some better data validation to avoid this.

chirpstack-docker-helium-route-updater-1             | panic: rpc error: code = Internal desc = Invalid string length
chirpstack-docker-helium-route-updater-1             |
chirpstack-docker-helium-route-updater-1             | goroutine 33 [running]:
chirpstack-docker-helium-route-updater-1             | github.com/thisisdevelopment/helium-route-updater/pkg/lns.(*ChirpstackClient).GetDevice(0xc000428c00, {0x0, 0x0})
chirpstack-docker-helium-route-updater-1             |  /app/pkg/lns/chirpstack.go:167 +0x35b
chirpstack-docker-helium-route-updater-1             | github.com/thisisdevelopment/helium-route-updater/pkg/lns.(*ChirpstackClient).Listen(0xc000428c00, 0xbedff8?, 0xc000010140?)
chirpstack-docker-helium-route-updater-1             |  /app/pkg/lns/chirpstack.go:87 +0xc13
chirpstack-docker-helium-route-updater-1             | created by main.main
chirpstack-docker-helium-route-updater-1             |  /app/cmd/helium-route-updater/main.go:39 +0x2ea
ederuiter commented 1 year ago

Hmm interesting, I did not expect invalid requests to be logged there.

My first thought was this is an easy fix .. I just need to filter on the request status .. but apparently that is not available in the request log :disappointed:
The only available fields are service, method and metadata .. and metadata only contains response headers starting with (x-log-)

I think this an oversight on the chirpstack side. I will create an issue/pr for that on the chirpstack repo

For now I will add some code to handle these errors more graceful