Skip to content

pymobiledevice3 sometimes hanging, blocked by a read while working with netmuxd #1583

@eigenphase

Description

@eigenphase

Test environment

  • Ubuntu noble
  • iPhone 14 Pro iOS 26

Describe the bug
Sometimes pymobiledevice3 hangs in the background. It seems read syscall is blocking...

To Reproduce
Unfortunately hard to reproduce. Happens every couple of days.

Additional context

I have set up pymobiledevice3 to pull backups of my iPhone automatically and wrapped a script around. This script has a lock that allows only one execution (via PID and lock file). Every few days, pymobiledevice3 hangs and then no new instances of my script can run until I kill the old instance. It is not clear under which condition it hangs.

In the latest instance, it hangs with this command in my script:

# 2. check if iPhone is reachable                                                                                                                                                                                                                   
if ! "$PYMOBILEDEVICE3" usbmux list 2>/dev/null | grep -q "$UDID"; then                                                                                                                                                                                                                                                                                                                                                                                
    exit 0                                                                                                                                                                                                                                          
fi  

The relevant process tree looks like this:

 324135 ?        S      0:00  \_ /usr/sbin/CRON -f -P
 324137 ?        Ss     0:00      \_ /bin/sh -c /home/user/scripts/miPhone_backup.sh >> /home/user/scripts/miPhone_backup.log
 324140 ?        S      0:00          \_ /bin/bash /home/user/scripts/miPhone_backup.sh
 324144 ?        S      0:00              \_ /home/user/.local/share/pipx/venvs/pymobiledevice3/bin/python /home/user/.local/bin/pymobiledevice3 usbmux list
 324145 ?        S      0:00              \_ grep -q 00008538-000819993413C01E

I tried attaching strace to the process but unfortunately can't find more details than a read from file descriptor 3 is blocking:

$ sudo strace -p 324144
[sudo] password for user:
strace: Process 324144 attached
read(3, ^Cstrace: Process 324144 detached
 <detached ...>

Below is the stack trace via py-spy:

$ sudo /home/user/.local/bin/py-spy dump --pid 324144
Process 324144: /home/user/.local/share/pipx/venvs/pymobiledevice3/bin/python /home/user/.local/bin/pymobiledevice3 usbmux list
Python v3.12.3 (/usr/bin/python3.12)

Thread 324144 (idle): "MainThread"
    do_handshake (ssl.py:1320)
    _create (ssl.py:1042)
    wrap_socket (ssl.py:455)
    ssl_start (pymobiledevice3/service_connection.py:361)
    validate_pairing (pymobiledevice3/lockdown.py:399)
    _handle_autopair (pymobiledevice3/lockdown.py:627)
    create (pymobiledevice3/lockdown.py:200)
    create_using_usbmux (pymobiledevice3/lockdown.py:878)
    usbmux_list (pymobiledevice3/cli/usbmux.py:111)
    invoke_with_dependencies (typer_injector/_inject.py:107)
    wrapper (typer_injector/_inject.py:136)
    wrapper (typer/main.py:1514)
    invoke (click/core.py:824)
    invoke (click/core.py:1269)
    invoke (click/core.py:1873)
    invoke (click/core.py:1873)
    _main (typer/core.py:188)
    main (typer/core.py:795)
    __call__ (click/core.py:1485)
    __call__ (typer/main.py:1135)
    invoke_cli_with_error_handling (pymobiledevice3/__main__.py:315)
    main (pymobiledevice3/__main__.py:425)
    <module> (pymobiledevice3:6)

The backup target is stored on a local SSD (ZFS dataset) so it can't really be blocking there.

If there is any other debug info I can provide I am happy to share once the issue pops up next time (probably in a few days).

I set up this script about a week ago and I am very excited about it but this issue happened now already the third time.

At least one other time it did not hang on "usbmux list" but "backup2 backup --udid xxx --no-full" call.

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions