@@ -47,7 +47,9 @@ import io.livekit.android.util.TTLMap
4747import io.livekit.android.util.flow
4848import io.livekit.android.util.flowDelegate
4949import io.livekit.android.util.nullSafe
50+ import io.livekit.android.util.rethrowIfCancellationSignal
5051import io.livekit.android.util.withCheckLock
52+ import io.livekit.android.util.withDeadline
5153import io.livekit.android.webrtc.DataChannelManager
5254import io.livekit.android.webrtc.DataPacketBuffer
5355import io.livekit.android.webrtc.DataPacketItem
@@ -71,7 +73,6 @@ import kotlinx.coroutines.runBlocking
7173import kotlinx.coroutines.suspendCancellableCoroutine
7274import kotlinx.coroutines.sync.Mutex
7375import kotlinx.coroutines.sync.withLock
74- import kotlinx.coroutines.withTimeout
7576import kotlinx.coroutines.withTimeoutOrNull
7677import kotlinx.coroutines.yield
7778import livekit.LivekitModels
@@ -397,7 +398,7 @@ internal constructor(
397398 }
398399
399400 // Suspend until signal client receives message confirming track publication.
400- return withTimeout (20 .seconds) {
401+ return withDeadline (20 .seconds) {
401402 suspendCancellableCoroutine { cont ->
402403 synchronized(pendingTrackResolvers) {
403404 pendingTrackResolvers[cid] = cont
@@ -540,6 +541,7 @@ internal constructor(
540541 try {
541542 url = regionUrlProvider?.getNextBestRegionUrl() ? : url
542543 } catch (e: Exception ) {
544+ e.rethrowIfCancellationSignal()
543545 LKLog .d(e) { " Exception while getting next best region url while reconnecting." }
544546 }
545547 }
@@ -589,6 +591,7 @@ internal constructor(
589591 listener?.onFullReconnecting()
590592 joinImpl(url!! , token, connectOptions, lastRoomOptions ? : RoomOptions ())
591593 } catch (e: Exception ) {
594+ e.rethrowIfCancellationSignal()
592595 LKLog .w(e) { " Error during reconnection." }
593596 // reconnect failed, retry.
594597 continue
@@ -612,6 +615,7 @@ internal constructor(
612615 }
613616 client.onReadyForResponses()
614617 } catch (e: Exception ) {
618+ e.rethrowIfCancellationSignal()
615619 LKLog .w(e) { " Error during reconnection." }
616620 // ws reconnect failed, retry.
617621 continue
@@ -716,6 +720,7 @@ internal constructor(
716720 try {
717721 ensurePublisherConnected(dataPacket.kind)
718722 } catch (e: Exception ) {
723+ e.rethrowIfCancellationSignal()
719724 return Result .failure(e)
720725 }
721726
@@ -769,6 +774,7 @@ internal constructor(
769774
770775 channel.send(buf)
771776 } catch (e: Exception ) {
777+ e.rethrowIfCancellationSignal()
772778 return Result .failure(e)
773779 }
774780 return Result .success(Unit )
@@ -802,6 +808,7 @@ internal constructor(
802808 try {
803809 ensurePublisherConnected(kind)
804810 } catch (e: Exception ) {
811+ e.rethrowIfCancellationSignal()
805812 return
806813 }
807814 val manager = dataChannelManagerForKind(kind) ? : return
0 commit comments