Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cache invalidation of disconnected lockdown client #540

Merged
merged 4 commits into from
Aug 2, 2024
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
7 changes: 5 additions & 2 deletions src/fruity/device-monitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ namespace Frida.Fruity {
transports.clear ();
}

public UsbmuxDevice? find_usbmux_device () throws Error {
public UsbmuxDevice? find_usbmux_device () {
var transport = transports.first_match (t => t.usbmux_device != null && t.connection_type == USB);
if (transport == null)
transport = transports.first_match (t => t.usbmux_device != null);
Expand Down Expand Up @@ -287,15 +287,18 @@ namespace Frida.Fruity {

private async void process_usbmux_lockdown_service_requests () {
UsbmuxLockdownServiceRequest? req;
bool already_invalidated = false;
while ((req = usbmux_lockdown_service_requests.peek ()) != null) {
try {
if (cached_usbmux_lockdown_client == null)
cached_usbmux_lockdown_client = yield open_usbmux_lockdown_client (req.cancellable);
var stream = yield cached_usbmux_lockdown_client.start_service (req.service_name, req.cancellable);
req.promise.resolve (stream);
} catch (GLib.Error e) {
if (e is Error.TRANSPORT && cached_usbmux_lockdown_client != null) {
if (e is LockdownError.CONNECTION_CLOSED && cached_usbmux_lockdown_client != null &&
!already_invalidated) {
cached_usbmux_lockdown_client = null;
already_invalidated = true;
continue;
}
req.promise.reject ((e is LockdownError.INVALID_SERVICE)
Expand Down
3 changes: 3 additions & 0 deletions src/fruity/lockdown.vala
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ namespace Frida.Fruity {
}

private static LockdownError error_from_service (PlistServiceError e) {
if (e is PlistServiceError.CONNECTION_CLOSED)
return new LockdownError.CONNECTION_CLOSED ("%s", e.message);
return new LockdownError.PROTOCOL ("%s", e.message);
}

Expand All @@ -274,6 +276,7 @@ namespace Frida.Fruity {
}

public errordomain LockdownError {
CONNECTION_CLOSED,
INVALID_SERVICE,
NOT_PAIRED,
UNSUPPORTED,
Expand Down
Loading