From 787cb1e33dc0828fbfd1f579f1f0de93e24c980e Mon Sep 17 00:00:00 2001 From: Yohan Totting Date: Fri, 14 Jun 2024 15:30:05 +0700 Subject: [PATCH] fix afterClosed call more than once --- client.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 1d90442..a962620 100644 --- a/client.go +++ b/client.go @@ -1034,10 +1034,14 @@ func (c *Client) processPendingTracks() { // make sure to call this when client's done to clean everything func (c *Client) afterClosed() { + c.mu.Lock() state := c.state.Load() - if state != ClientStateEnded { - c.state.Store(ClientStateEnded) + if state == ClientStateEnded { + return } + c.mu.Unlock() + + c.state.Store(ClientStateEnded) c.internalDataChannel.Close()