Skip to content

Commit 70d3dde

Browse files
clamped the effectiveTimeout and fixed the comment (#821)
So the problem is that the performRpc is a public function, and we never sanity check if users provide values larger than the connection_timeout, which might cause unexpected behavior. This PR fixes the comment and also clamp the connection response timeout if needed. See similar PR on JS SDK: livekit/client-sdk-js#1694
1 parent 4e94136 commit 70d3dde

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

.changes/clamp-response-timeout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch type="fixed" "clamp response timeout in performRpc to minimal 1s"

Sources/LiveKit/Participant/LocalParticipant+RPC.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ public extension LocalParticipant {
2424
/// - destinationIdentity: The identity of the destination participant
2525
/// - method: The method name to call
2626
/// - payload: The payload to pass to the method
27-
/// - responseTimeout: Timeout for receiving a response after initial connection. (default 10s)
27+
/// - responseTimeout: Timeout for receiving a response after the initial connection (in seconds).
28+
/// If a value less than 8s is provided, it will be automatically clamped to 8s
29+
/// to ensure sufficient time for round-trip latency buffering.
30+
/// Default: 15s.
2831
/// - Returns: The response payload
2932
/// - Throws: RpcError on failure. Details in RpcError.message
3033
func performRpc(destinationIdentity: Identity,
@@ -40,8 +43,8 @@ public extension LocalParticipant {
4043

4144
let requestId = UUID().uuidString
4245
let maxRoundTripLatency: TimeInterval = 7
43-
let effectiveTimeout = responseTimeout - maxRoundTripLatency
44-
46+
let minEffectiveTimeout: TimeInterval = 1
47+
let effectiveTimeout = max(responseTimeout - maxRoundTripLatency, minEffectiveTimeout)
4548
try await publishRpcRequest(destinationIdentity: destinationIdentity,
4649
requestId: requestId,
4750
method: method,

Tests/LiveKitTestSupport/Room.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public extension Room {
210210

211211
public final class RoomWatcher<T: Decodable & Sendable>: RoomDelegate, Sendable {
212212
public let id: String
213-
public let didReceiveDataCompleters = CompleterMapActor<T>(label: "Data receive completer", defaultTimeout: 10)
213+
public let didReceiveDataCompleters = CompleterMapActor<T>(label: "Data receive completer", defaultTimeout: 15)
214214

215215
// MARK: - Private
216216

0 commit comments

Comments
 (0)