Skip to content

Commit 91d93ad

Browse files
clamp the response timeout to at least 1s (#783)
1 parent e65d1f2 commit 91d93ad

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

livekit-android-sdk/src/main/java/io/livekit/android/room/participant/LocalParticipant.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,9 @@ internal constructor(
10981098
// Maximum amount of time it should ever take for an RPC request to reach the destination, and the ACK to come back
10991099
// This is set to 7 seconds to account for various relay timeouts and retries in LiveKit Cloud that occur in rare cases
11001100
val maxRoundTripLatency = 7.seconds
1101+
// Minimum allowed effective timeout to ensure the RPC lifecycle always has at least
1102+
// one second to complete, even after accounting for round-trip latency.
1103+
val minEffectiveTimeout = 1.seconds
11011104

11021105
if (payload.byteLength() > RTCEngine.MAX_DATA_PACKET_SIZE) {
11031106
throw RpcError.BuiltinRpcError.REQUEST_PAYLOAD_TOO_LARGE.create()
@@ -1111,13 +1114,14 @@ internal constructor(
11111114
}
11121115

11131116
val requestId = UUID.randomUUID().toString()
1114-
1117+
// Ensure the effective response timeout is not less than 1 second
1118+
val effectiveTimeout = (responseTimeout - maxRoundTripLatency).coerceAtLeast(minEffectiveTimeout)
11151119
val result = publishRpcRequest(
11161120
destinationIdentity = destinationIdentity,
11171121
requestId = requestId,
11181122
method = method,
11191123
payload = payload,
1120-
responseTimeout = responseTimeout - maxRoundTripLatency,
1124+
responseTimeout = effectiveTimeout,
11211125
)
11221126

11231127
if (result.isFailure) {

livekit-android-sdk/src/main/java/io/livekit/android/room/rpc/RpcManager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ interface RpcManager {
7979
* @param method The method name to call.
8080
* @param payload The payload to pass to the method.
8181
* @param responseTimeout Timeout for receiving a response after initial connection.
82+
* If a value less than 8s is provided, it will be automatically clamped to 8s
83+
* to ensure sufficient time for round-trip latency buffering.
8284
* Defaults to 15 seconds.
8385
* @return The response payload.
8486
* @throws RpcError on failure. Details in [RpcError.message].

0 commit comments

Comments
 (0)