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

socket.c socket_receive_timeout() can hang on Windows #41

Closed
sctol opened this issue Feb 23, 2024 · 6 comments
Closed

socket.c socket_receive_timeout() can hang on Windows #41

sctol opened this issue Feb 23, 2024 · 6 comments

Comments

@sctol
Copy link

sctol commented Feb 23, 2024

Running into a hang with libimobiledevice on Windows tracked down to socket_receive_timeout() of socket.c, line 1296.

recv() is returning -1 on a socket with errno == 0 when the remote peer disconnected while there are still bytes to read (res > 0)

Line 1296 reads "return -errno;;"

Suggest replacing this with "return (errno == 0) ? -ECONNRESET : -errno;"

@nikias
Copy link
Member

nikias commented Feb 23, 2024

I think the real way to handle this is using WSAGetLastError(). In regards to
#14
I am working on some modifications, specifically making sure that errno is set to a value based on whatever WSAGetLastError() returned.

@sctol
Copy link
Author

sctol commented Feb 23, 2024

Thank you for taking a look at this. I forgot to mention the way I was getting the libimobiledevice to hang was to start idevicebackup2 backup on a paired iPhone, then disconnect the USB cable about half way through the file sends. Maybe 5-10% of the time the idevicebackup2 would lockup with the CPU 100% busy reading nothing.

@sctol
Copy link
Author

sctol commented Feb 29, 2024

I did a bit of testing this evening, adding a statement to socket_recieve_timeout() that prints WSAGetLastError(), errno, and the results from socket_check_fd() and recv(). When the disconnect occurs, socket_check_fd() returned 1, recv() returned -1 and WSAGetLastError is 10053 (connection aborted). Errno has one of the following values: 0, 2, 7, 17 with 17 being the most common. If only WSA were portable to the BSD socket standard, including errno.

@nikias
Copy link
Member

nikias commented Feb 29, 2024

That helps. As mentioned I am in the process of integrating WSAGetLastError into the code to make sure we have proper errno set. You cannot trust errno in regards to any socket related error/status.

@nikias
Copy link
Member

nikias commented Mar 6, 2024

Came up with this fc10c88.

@nikias
Copy link
Member

nikias commented May 4, 2024

This should be resolved by now. If not feel free to re-open.

@nikias nikias closed this as completed May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants