metalmatze / transmission-exporter

Prometheus exporter for Transmission metrics, written in Go.
MIT License
99 stars 40 forks source link

panic: runtime error: invalid memory address or nil pointer dereference #20

Open luma91 opened 4 years ago

luma91 commented 4 years ago

Trying to run in portainer, getting this error in the logs when accessing the metrics page which kills the container.

luma91 commented 4 years ago

Same issue trying to run this directly in a ubuntu vm

2020/01/03 14:57:42 failed to get session: invalid character '<' looking for beginning of value panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7bad29]

metalmatze commented 4 years ago

I would guess that it is most likely an authentication issues, as the exporter expects JSON to be returned in the response but something else is read from the body.

metalmatze commented 4 years ago

It shouldn't panic though...

luma91 commented 4 years ago

Hmm. I dont have a user / pass for my transmission. Do you think that might do it? Update: Okay I set a basic user / pass in my transmission server and now transmission exporter works.

DanielYWoo commented 4 years ago

same here

appuser@home-nas:/opt/exporter_transmission$ docker logs exporter_transmission
2020/03/30 15:52:31 starting transmission-exporter
2020/03/30 15:52:31 no .env present
2020/03/30 15:52:32 failed to get session stats: invalid character '<' looking for beginning of value
2020/03/30 15:52:32 failed to get session: invalid character '<' looking for beginning of value
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7bbc6f]

goroutine 6 [running]:
main.(*SessionStatsCollector).Collect(0xc0000968a0, 0xc000180060)
    /go/src/github.com/metalmatze/transmission-exporter/cmd/transmission-exporter/session_stats_collector.go:118 +0xcf
github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1()
    /go/pkg/mod/github.com/prometheus/client_golang@v0.9.0-pre1.0.20181010161331-7866eead363e/prometheus/registry.go:430 +0x19d
created by github.com/prometheus/client_golang/prometheus.(*Registry).Gather
    /go/pkg/mod/github.com/prometheus/client_golang@v0.9.0-pre1.0.20181010161331-7866eead363e/prometheus/registry.go:522 +0xe12
andrzejressel commented 4 years ago

I got this error when I was using hostname that was not in rpc-host-whitelist

northys commented 2 years ago

@metalmatze it happens for me when transmission is moving files from download directory to final destination which causes timeouts of transmission rpc. the whole transmission is stuck at this point because it's single thread app and when it copies files it doesn't do anything else.

when the copying completes it starts to work again though... it looks like bad handling of rpc errors / timeouts but i'm not a golang dev so i don't understand the code much.

transmission-exporter_1  | 2022/03/13 00:07:16 failed to get session stats: Post http://172.17.0.1:9091/transmission/rpc: dial tcp 172.17.0.1:9091: i/o timeout
transmission-exporter_1  | panic: runtime error: invalid memory address or nil pointer dereference
transmission-exporter_1  | [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7bbc6f]
transmission-exporter_1  | 
transmission-exporter_1  | goroutine 41 [running]:
transmission-exporter_1  | main.(*SessionStatsCollector).Collect(0xc0001221e0, 0xc00011e0c0)
transmission-exporter_1  |  /go/src/github.com/metalmatze/transmission-exporter/cmd/transmission-exporter/session_stats_collector.go:118 +0xcf
transmission-exporter_1  | github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1()
transmission-exporter_1  |  /go/pkg/mod/github.com/prometheus/client_golang@v0.9.0-pre1.0.20181010161331-7866eead363e/prometheus/registry.go:430 +0x19d
transmission-exporter_1  | created by github.com/prometheus/client_golang/prometheus.(*Registry).Gather
transmission-exporter_1  |  /go/pkg/mod/github.com/prometheus/client_golang@v0.9.0-pre1.0.20181010161331-7866eead363e/prometheus/registry.go:522 +0xe12
metalmatze commented 2 years ago

Thanks for commenting with that feedback. I wasn't aware of the single-threaded nature of Transmission and this being a root cause. :+1:

northys commented 2 years ago

I checked the exporter code and from that little I know about golang I would say there should be no problem. You are correctly checking that err is nil but the code seems tk go through that condition and later fails because there is no data in the response.

Do you have any idea what could be the cause of this error?