Open diegoe opened 4 years ago
Some further investigation has led me to believe that this issue is specifically triggered as follows:
If you trigger a "lock down" in the iPhone (pressing lock multiple times to make it forget recently trusted USB devices) -- you can eliminate the stalling. Alternatively, you can directly boot into Linux.
It appears that the iPhone exposes more of its information when it "trusts" the MacBook. For example, in the scenario above, I can --auto-detect
the iPhone. However, if I directly boot into Linux or trigger a "lock down", I can't.
My hypothesis is that the iPhone believes that Linux is still the same system as when it authorized macOS, but libgphoto2 is somehow not meeting some expectation in the conversation. This could be argued as an issue with the lock/unlock feature of the iPhone, but I believe that the original question is still valid: should libgphoto2 stall for so long when there's some kind of broken back and forth with an iOS device? Perhaps the quirk in that part of the code needs to be updated?
3. The iPhone still "trusts" the MacBook, but the timeout/stalling in gphoto2 happens
Commenting about this part (with my libimobiledevice Debian maintainer background and as an iPhone user on Linux): this is not how iPhone pairing works. The authentication/pairing is done with a daemon running on the host (whether MacOS/iTunes or Linux/usbmuxd), so pairing on MacOS and rebooting on Linux should give an โunpairedโ iPhone anyway.
Note that USB restricted mode on recent iOS can also alter the behavior: before first passcode entry or the โlock downโ you mention (for example entering SOS mode and cancelling it) means the USB device won't even appear to Linux.
Is libgphoto2 waiting for usbmuxd pairing (eg. trust), or for a screen unlock?
If the former, it might be possible to only create the volumes (and try to mount those volumes) in gvfs/GNOME when the pairing has already been done.
Today I was having delays on session login so I tried again to reproduce with gphoto2
on the command line.
I also stopped the system's usbmuxd
and ran /usr/sbin/usbmuxd --user usbmux --systemd -v
to monitor for anything weird, but it doesn't seem to be stalling on anything from usbmuxd:
[21:18:10.815][4] Client 14 is going to be disconnected: /usr/libexec/upowerd[1183]
[21:18:10.886][4] Client 13 is going to be disconnected: /usr/libexec/upowerd[1183]
[21:20:10.789][4] Client 13 accepted: /usr/libexec/upowerd[1183]
[21:20:10.790][4] Client connected to device 1 (9->62078)
[21:20:10.792][4] Client 14 accepted: /usr/libexec/upowerd[1183]
[21:20:10.792][4] Client 14 connection closed
[21:20:10.793][4] Client 14 is going to be disconnected: /usr/libexec/upowerd[1183]
[21:20:10.793][4] Client 14 accepted: /usr/libexec/upowerd[1183]
[21:20:10.793][4] Client 14 connection closed
[21:20:10.793][4] Client 14 is going to be disconnected: /usr/libexec/upowerd[1183]
[21:20:10.800][4] Client 14 accepted: /usr/libexec/upowerd[1183]
[21:20:10.800][4] Client 14 connection closed
[21:20:10.800][4] Client 14 is going to be disconnected: /usr/libexec/upowerd[1183]
[21:20:10.874][4] Client 13 is going to be disconnected: /usr/libexec/upowerd[1183]
[21:22:10.773][4] Client 13 accepted: /usr/libexec/upowerd[1183]
[21:22:10.775][4] Client connected to device 1 (10->62078)
[21:22:10.777][4] Client 14 accepted: /usr/libexec/upowerd[1183]
[21:22:10.778][4] Client 14 connection closed
[21:22:10.778][4] Client 14 is going to be disconnected: /usr/libexec/upowerd[1183]
[21:22:10.778][4] Client 14 accepted: /usr/libexec/upowerd[1183]
[21:22:10.779][4] Client 14 connection closed
[21:22:10.779][4] Client 14 is going to be disconnected: /usr/libexec/upowerd[1183]
[21:22:10.789][4] Client 14 accepted: /usr/libexec/upowerd[1183]
[21:22:10.790][4] Client 14 connection closed
[21:22:10.790][4] Client 14 is going to be disconnected: /usr/libexec/upowerd[1183]
[21:22:10.866][4] Client 13 is going to be disconnected: /usr/libexec/upowerd[1183]
Here are the logs for locked/unlocked gphoto2 --storage-info --debug
:
After running the above test, I tried the following:
In the last few lock/unlock cycles, gphoto2 would respond instantly if I unlocked the device while it was stalled:
Describe the bug libgphoto2 stalls when querying a locked iPhone6.
Name the camera Apple iPhone 5 (PTP mode) usb:001,016
libgphoto2 and gphoto2 version gphoto2 2.5.23.1 gcc, popt(m), exif, no cdk, no aa, jpeg, readline libgphoto2 2.5.24.1 standard camlibs, gcc, ltdl, EXIF libgphoto2_port 0.12.0 iolibs: disk ptpip serial usb1 usbdiskdirect usbscsi, gcc, ltdl, EXIF, USB, serial without locking
To Reproduce I ran into this bug while debugging a long login time in GNOME sessions while my iPhone was plugged and locked. The delays in login time were noticeable and always stalling in gvfs' gphoto2 volume monitor backend.
After some investigation I found out that
camlibs/ptp2
has special-case'd Apple devices in light of the locked/unlocked behavior of not allowing access to files unless unlocked:This behavior translates into almost 18 seconds of overhead in my system (see attached logs). Even more, anything waiting on
camera_init()
stalls, asptp_wait_event()
seems to be 100% sync.I believe this might be a left over of older iOS behavior with respect to the locked/unlocked flow. If my iPhone is locked, I expect my application (gphoto2 cli, or GNOME, or etc) to report said thing instead of mysteriously stalling for 20 seconds. On macOS, non-gphoto2 apps simply omit the iPhone as a source, and some report "Unlock your iPhone to see photos". I believe this behavior is more reasonable.
I'm admittedly not super familiar with libgphoto2 code, but I would propose that said
ptp_wait_event
be changed toptp_queue_event
so that it doesn't stall. I guessptp_check_event
should work too, but you get the idea.I'm attaching logs for the behavior of gphoto2 on master, with my changes, and in both cases with the iPhone locked/unlocked.
Reference: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=942832
Current master behavior
With ptp_queue_event
Logs