Skip to content
Open
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
8 changes: 8 additions & 0 deletions .changeset/lukas_reconnect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
livekit: patch
livekit-api: patch
livekit-ffi: patch
livekit-uniffi: patch
---

harden reconnect behaviour - #1148 (@lukasIO)
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions livekit-api/src/signal_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,29 @@ impl SignalClient {
if matches!(&err, SignalError::WsError(WsError::Http(e)) if e.status() != 403) {
log::error!("unexpected signal error: {}", err.to_string());
}
let urls = RegionUrlProvider::fetch_region_urls(url, token).await?;
let mut last_err = err;

// Fetching region URLs is best-effort. `fetch_region_urls`
// already returns an empty list for non-cloud (direct /
// self-hosted) URLs, so those skip the fallback entirely. If the
// fetch itself fails (e.g. the region endpoint is unreachable),
// that must NOT be fatal: log a warning and fall back to the
// original connection error rather than masking it with the
// fetch error.
let urls = match RegionUrlProvider::fetch_region_urls(url, token).await {
Ok(urls) => urls,
Err(region_err) => {
log::warn!(
"failed to fetch region urls: {region_err}; surfacing original connection error"
);
return Err(err);
}
};

// With no region URLs to try, this surfaces the original error.
// Otherwise we keep the most recent region attempt error, so that
// if every region fails the caller sees why the last region
// connection failed.
let mut last_err = err;
for url in urls.iter() {
log::info!("fallback connection to: {}", url);
match SignalInner::connect(url, token, options.clone(), publisher_offer.clone())
Expand All @@ -226,7 +246,7 @@ impl SignalClient {
Ok((inner, join_response, stream_events)) => {
return Ok(handle_success(inner, join_response, stream_events))
}
Err(err) => last_err = err,
Err(region_conn_err) => last_err = region_conn_err,
}
}

Expand Down
9 changes: 9 additions & 0 deletions livekit-ffi-node-bindings/proto/room_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ export declare enum SimulateScenarioKind {
* @generated from enum value: SIMULATE_FULL_RECONNECT = 7;
*/
SIMULATE_FULL_RECONNECT = 7,

/**
* Asks the server to drop the signalling connection during the next resume,
* then triggers a resume locally. The resume cannot complete, so the engine
* escalates to a full reconnect — exercising the resume→full escalation path.
*
* @generated from enum value: SIMULATE_DISCONNECT_SIGNAL_ON_RESUME = 8;
*/
SIMULATE_DISCONNECT_SIGNAL_ON_RESUME = 8,
}

/**
Expand Down
1 change: 1 addition & 0 deletions livekit-ffi-node-bindings/proto/room_pb.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const SimulateScenarioKind = /*@__PURE__*/ proto2.makeEnum(
{no: 5, name: "SIMULATE_FORCE_TCP"},
{no: 6, name: "SIMULATE_FORCE_TLS"},
{no: 7, name: "SIMULATE_FULL_RECONNECT"},
{no: 8, name: "SIMULATE_DISCONNECT_SIGNAL_ON_RESUME"},
],
);

Expand Down
4 changes: 4 additions & 0 deletions livekit-ffi/protocol/room.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ enum SimulateScenarioKind {
// Asks the server to send `LeaveRequest{Reconnect}`, forcing a full
// reconnect (new RtcSession; SDK republishes existing local tracks).
SIMULATE_FULL_RECONNECT = 7;
// Asks the server to drop the signalling connection during the next resume,
// then triggers a resume locally. The resume cannot complete, so the engine
// escalates to a full reconnect — exercising the resume→full escalation path.
SIMULATE_DISCONNECT_SIGNAL_ON_RESUME = 8;
}
message SimulateScenarioRequest {
required uint64 room_handle = 1;
Expand Down
3 changes: 3 additions & 0 deletions livekit-ffi/src/server/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ fn on_simulate_scenario(
proto::SimulateScenarioKind::SimulateForceTcp => SimulateScenario::ForceTcp,
proto::SimulateScenarioKind::SimulateForceTls => SimulateScenario::ForceTls,
proto::SimulateScenarioKind::SimulateFullReconnect => SimulateScenario::FullReconnect,
proto::SimulateScenarioKind::SimulateDisconnectSignalOnResume => {
SimulateScenario::DisconnectSignalOnResume
}
};

let ffi_room = server.retrieve_handle::<room::FfiRoom>(request.room_handle)?.clone();
Expand Down
1 change: 1 addition & 0 deletions livekit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ anyhow = "1.0.99"
test-log = "0.2.18"
test-case = "3.3"
serial_test = "3.0"
http = "1.1"
Loading
Loading