poco icon indicating copy to clipboard operation
poco copied to clipboard

HTTPSClientSession read infinite loop on IOS

Open zhufan opened this issue 3 years ago • 2 comments

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.

zhufan avatar Apr 07 '22 04:04 zhufan

@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?

aleks-f avatar Apr 16 '22 20:04 aleks-f

yes, I have verified。Revert https://github.com/pocoproject/poco/commit/f7ba58c80f387b34e7b03aa77d950d738355d46a , infinite loop no longer exist.

zhufan avatar Jul 20 '22 04:07 zhufan

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

github-actions[bot] avatar Jul 21 '23 02:07 github-actions[bot]

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

github-actions[bot] avatar Oct 01 '23 02:10 github-actions[bot]