libimobiledevice / libusbmuxd

A client library to multiplex connections from and to iOS devices
https://libimobiledevice.org
GNU Lesser General Public License v2.1
589 stars 270 forks source link

libusbmuxd and libimobiledevice-glue built for Windows can lockup on a disconnect #131

Open sctol opened 1 year ago

sctol commented 1 year ago

Ran into an issue using libimobiledevice tools locking up with a iOS device connected with a faulty USB cable and tracked it down to libusbmuxd and libimobiledevice-glue.

Code linked against the Windows MSVC runtime library using its send(), recv(), and select() functions can return on a hard disconnect or connection reset with errno set to 0.

One possible workaround would be to replace returns of -errno with (errno == 0) ? -ECONNRESET : -errno

sctol commented 7 months ago

Still running into lockup issues on Windows with send() in libusbmuxd and recv() in libimobiledevice-glue/socket.c

Specifically at lines 210 and 224 of libusbmuxd.c, suggest changing "res = -errno;" with "res = (errno == 0) ? -ECONNRESET : -errno;"

and at line 1595, change "num_sent = errno;" with "num_sent = (errno == 0) ? ECONNRESET : errno;"

All because errno can still be zero on a socket error with send() and recv() on Windows.

nikias commented 7 months ago

See my comment here: https://github.com/libimobiledevice/libimobiledevice-glue/issues/41#issuecomment-1961868247 working on a solution.