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

HTTPSClientSession read infinite loop on IOS #3557

Closed
zhufan opened this issue Apr 7, 2022 · 4 comments
Closed

HTTPSClientSession read infinite loop on IOS #3557

zhufan opened this issue Apr 7, 2022 · 4 comments

Comments

@zhufan
Copy link

zhufan commented Apr 7, 2022

Environment

IOS

Current Behavior

Create a HTTPSClientSession, sendRequest and receiveResponse. Move app to background and move it back to foreground a few minutes later. Then the underlying socket will be invalid and read function fall into infinite loop.

Expect Behavior

read function return error when socket is invalid.

Reason

int SecureSocketImpl::receiveBytes(void* buffer, int length, int flags)
{
poco_assert (_pSocket->initialized());
poco_check_ptr (_pSSL);
int rc;
if (_needHandshake)
{
rc = completeHandshake();
if (rc == 1)
verifyPeerCertificate();
else
return rc;
}
do
{
rc = SSL_read(_pSSL, buffer, length);
}
while (mustRetry(rc));
if (rc <= 0)
{
return handleError(rc);
}
return rc;
}

when socket is invalid, SSL_read return -1, but mustRetry always return true, so receiveBytes fall into infinite loop. This is because poll always return true when socket is invalid(platform specific).
case SSL_ERROR_WANT_READ:
if (_pSocket->getBlocking())
{
if (_pSocket->poll(_pSocket->getReceiveTimeout(), Poco::Net::Socket::SELECT_READ))
return true;
else
throw Poco::TimeoutException();
}
break;

Possible Solution

SSL_MODE_AUTO_RETRY is set by poco:

SSL_CTX_set_mode(_pSSLContext, SSL_MODE_AUTO_RETRY);

and socket is blocking, there is no need to retry when SSL_read return error, reference: https://www.openssl.org/docs/man1.1.1/man3/SSL_read.html
revert f7ba58c can fix it.

@obiltschnig obiltschnig self-assigned this Apr 7, 2022
@obiltschnig obiltschnig added the bug label Apr 7, 2022
@obiltschnig obiltschnig added this to the Release 1.11.2 milestone Apr 7, 2022
@aleks-f aleks-f changed the title HTTPSClientSession read function fall into infinite loop on IOS HTTPSClientSession read infinite loop on IOS Apr 16, 2022
@aleks-f
Copy link
Member

aleks-f commented Apr 16, 2022

@obiltschnig just revert f7ba58c ? Note that it was committed to fix the #1160 . Perhaps setting SSL_MODE_ENABLE_PARTIAL_WRITE would have helped with that one?

@zhufan did you verify that removing said commit makes the problem go away?

@aleks-f aleks-f self-assigned this Apr 16, 2022
@zhufan
Copy link
Author

zhufan commented Jul 20, 2022

yes, I have verified。Revert f7ba58c , infinite loop no longer exist.

@github-actions
Copy link

This issue is stale because it has been open for 365 days with no activity.

@github-actions github-actions bot added the stale label Jul 21, 2023
@github-actions
Copy link

github-actions bot commented Oct 1, 2023

This issue was closed because it has been inactive for 60 days since being marked as stale.

@github-actions github-actions bot closed this as completed Oct 1, 2023
@aleks-f aleks-f added fixed and removed stale labels Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants