rkosegi / tuya-smartplug-exporter

Prometheus exporter for Tuya-based smartplug devices
Apache License 2.0
14 stars 3 forks source link

Runtime Error - Slice bounds out of range #84

Closed Strimblaster closed 2 months ago

Strimblaster commented 2 months ago

Hi. I have been experiencing this error every now and then.

panic: runtime error: slice bounds out of range [:64] with capacity 63

goroutine 214410 [running]:
github.com/rkosegi/tuya-smartplug-exporter/pkg/proto.(*proto).decryptResponse(0xc00009fea8?, {0xc0003e2014, 0x3f, 0xec})
        /build/pkg/proto/client.go:93 +0x190
github.com/rkosegi/tuya-smartplug-exporter/pkg/proto.(*proto).Status(0x906a40?)
        /build/pkg/proto/client.go:67 +0x6d
github.com/rkosegi/tuya-smartplug-exporter/pkg/exporter.(*exporter).Collect(0xc0001aa000, 0xc00048ff60?)
        /build/pkg/exporter/exporter.go:54 +0x2e7
github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1()
        /go/pkg/mod/github.com/prometheus/client_golang@v1.18.0/prometheus/registry.go:455 +0x102
created by github.com/prometheus/client_golang/prometheus.(*Registry).Gather in goroutine 25385
        /go/pkg/mod/github.com/prometheus/client_golang@v1.18.0/prometheus/registry.go:466 +0x568

Everything works fine for days but randomly it crashs with the error. Could't figure out what causes it.

My setup: I have 3 smart plugs, every plug is 24/7 up except one that might not be reachable for prolonged periods of time but it seams to work fine despite that. Only throws a warning like:

ts=2024-04-27T22:00:28.303Z caller=exporter.go:56 level=warn msg="error during scrape" device=REDACTED error="dial tcp 192.168.9.189:6668: connect: no route to host"

Thanks and sorry for the lack of info.

rkosegi commented 2 months ago

Hi @Strimblaster, thank you for this report. If issue you're seeing is occasional, it's most likely caused by device itself. There is not much I can do about it. Please update to latest version 1.0.2 that has fix for similar situation. Instead of panic, you will see fancy error in log.