Fix #79497: issue with php_openssl_subtract_timeval() causing ssl connection errors #5422
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.
I stumbled upon this while debugging a strange issue with
stream_socket_client()where it randomly throws out errors when the connection timeout is set to below 1s. The logic to calculate time difference inphp_openssl_subtract_timeval()is wrong whena.tv_usec < b.tv_usec, causing connection errors before the timeout is reached.I have created a script to reproduce the issue - https://gist.github.com/joec4i/ef1b1156ed79e23487400c68a5f693cb
Before the patch
The number of errors may vary but as you can see, connection failures happened way before the 0.9s timeout.
After the patch
Please review. Thanks!