From 68a188dd194d27a3845a65f0ce04a388c6e4e557 Mon Sep 17 00:00:00 2001 From: Maneschi Romain Date: Mon, 13 Mar 2023 12:24:13 +0100 Subject: [PATCH] protect channel read with mutex --- librespot/player/player.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/librespot/player/player.go b/librespot/player/player.go index 9219427..af05919 100644 --- a/librespot/player/player.go +++ b/librespot/player/player.go @@ -4,11 +4,12 @@ import ( "bytes" "encoding/binary" "fmt" + "log" + "sync" + "github.com/librespot-org/librespot-golang/Spotify" "github.com/librespot-org/librespot-golang/librespot/connection" "github.com/librespot-org/librespot-golang/librespot/mercury" - "log" - "sync" ) type Player struct { @@ -111,7 +112,10 @@ func (p *Player) HandleCmd(cmd byte, data []byte) { // fmt.Printf("[player] Data on channel %d: %d bytes\n", channel, len(data[2:])) - if val, ok := p.channels[channel]; ok { + p.chanLock.Lock() + val, ok := p.channels[channel] + p.chanLock.Unlock() + if ok { val.handlePacket(data[2:]) } else { fmt.Printf("Unknown channel!\n")