Fix GH-10495: feof on OpenSSL stream hangs indefinitely #13487
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the issue with unbounded waiting on SSL_peek which can happen when only part of the record is fetched. It makes socket non blocking so it is possible to verify if OpenSSL is expecting some more data or if there is an error.
It should be noted that most of the changes are for handling situation where timeout is requested. This is however not used by the only two calls using the
PHP_STREAM_OPTION_CHECK_LIVENESS
option (php_stream_eof
andphp_stream_xport_create
). Both of them set 0 as value which means no waiting should happen. The case where some value is set and timeout should be used might be only used by some external extension but it is quite unlikely as those would most likely use higher level function and most of the time just check eof. But it is done to make the logic complete and at least somehow consistent. We should however change it in master so I will create a ticket for this.