Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,9 @@ internal constructor(
// Maximum amount of time it should ever take for an RPC request to reach the destination, and the ACK to come back
// This is set to 7 seconds to account for various relay timeouts and retries in LiveKit Cloud that occur in rare cases
val maxRoundTripLatency = 7.seconds
// Minimum allowed effective timeout to ensure the RPC lifecycle always has at least
// one second to complete, even after accounting for round-trip latency.
val minEffectiveTimeout = 1.seconds

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

val requestId = UUID.randomUUID().toString()

// Ensure the effective response timeout is not less than 1 second
val effectiveTimeout = (responseTimeout - maxRoundTripLatency).coerceAtLeast(minEffectiveTimeout)
val result = publishRpcRequest(
destinationIdentity = destinationIdentity,
requestId = requestId,
method = method,
payload = payload,
responseTimeout = responseTimeout - maxRoundTripLatency,
responseTimeout = effectiveTimeout,
)

if (result.isFailure) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ interface RpcManager {
* @param method The method name to call.
* @param payload The payload to pass to the method.
* @param responseTimeout Timeout for receiving a response after initial connection.
* If a value less than 8s is provided, it will be automatically clamped to 8s
* to ensure sufficient time for round-trip latency buffering.
* Defaults to 15 seconds.
* @return The response payload.
* @throws RpcError on failure. Details in [RpcError.message].
Expand Down