From 9a727bc78b3482d2a8e4177e8391f80902d19618 Mon Sep 17 00:00:00 2001 From: boks1971 Date: Mon, 20 Nov 2023 11:38:07 +0530 Subject: [PATCH] move OnClose back to defer, need to deal with race differently --- signalclient.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/signalclient.go b/signalclient.go index c8741c93..c3f387a0 100644 --- a/signalclient.go +++ b/signalclient.go @@ -181,9 +181,6 @@ func (c *SignalClient) Close() { if isStarted { <-c.readerClosedCh } - if conn != nil && c.OnClose != nil { - c.OnClose() - } } func (c *SignalClient) SendICECandidate(candidate webrtc.ICECandidateInit, target livekit.SignalTarget) error { @@ -352,6 +349,10 @@ func (c *SignalClient) readWorker() { c.isStarted.Store(false) c.conn.Store(nil) close(c.readerClosedCh) + + if c.OnClose != nil { + c.OnClose() + } }() if pending := c.pendingResponse; pending != nil { c.handleResponse(pending)