devgianlu / go-librespot

Yet another open source Spotify client, written in Go.
GNU General Public License v3.0
133 stars 17 forks source link

nil pointer dereference in cmd/daemon/controls.go:42 #79

Open ius opened 1 month ago

ius commented 1 month ago

Not entirely sure how I triggered it, but there's a nil pointer dereference path in:

https://github.com/devgianlu/go-librespot/blob/b98dad6c894b94ee71d30d7ed54f2955ee7f53c4/cmd/daemon/controls.go#L40-L42

INFO[0007] loaded track "All It Takes" (paused: false, position: 399105ms, duration: 328800ms, prefetched: false)  uri="spotify:track:1H8RteGZrEFg5zuvy9Kljz"
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x94216e]

goroutine 124 [running]:
main.(*AppPlayer).prefetchNext(0xc000160780)
        /home/user/git/go-librespot/cmd/daemon/controls.go:42 +0x60e
created by main.(*AppPlayer).schedulePrefetchNext in goroutine 1
        /home/user/git/go-librespot/cmd/daemon/controls.go:56 +0x18c

I suppose p.secondaryStream.Media is nil here?

devgianlu commented 1 month ago

Media is only written upon initialization of the object and is surely non-nil at that time. I think secondaryStream became nil because prefetchNext runs in a goroutine and shouldn't access that stuff directly as the goroutine that handles command may be changing stuff (for example in loadCurrentTrack).

It is not trivial to fix, but hopefully shouldn't happen very often.