HTTPSClientSession read infinite loop on IOS
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
https://github.com/pocoproject/poco/blob/de61f0049175a941cc83c2615c3bdc5e947b89f9/NetSSL_OpenSSL/src/SecureSocketImpl.cpp#L312-L336 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). https://github.com/pocoproject/poco/blob/de61f0049175a941cc83c2615c3bdc5e947b89f9/NetSSL_OpenSSL/src/SecureSocketImpl.cpp#L437-L445
Possible Solution
SSL_MODE_AUTO_RETRY is set by poco: https://github.com/pocoproject/poco/blob/de61f0049175a941cc83c2615c3bdc5e947b89f9/NetSSL_OpenSSL/src/Context.cpp#L181 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 https://github.com/pocoproject/poco/commit/f7ba58c80f387b34e7b03aa77d950d738355d46a can fix it.
@obiltschnig just revert https://github.com/pocoproject/poco/commit/f7ba58c80f387b34e7b03aa77d950d738355d46a ? Note that it was committed to fix the https://github.com/pocoproject/poco/issues/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?
yes, I have verified。Revert https://github.com/pocoproject/poco/commit/f7ba58c80f387b34e7b03aa77d950d738355d46a , infinite loop no longer exist.
This issue is stale because it has been open for 365 days with no activity.
This issue was closed because it has been inactive for 60 days since being marked as stale.