Repository navigation
Fix accepting secure connections on PHP 8 - #37
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Accepting a connection on a secure server socket has thrown a
TypeErroron PHP 8 since the first release, because the accepted stream is handed tosocket_import_stream()in order to disable Nagle's algorithm, and that function cannot represent a TLS stream, so it returns false andsocket_set_option()rejects it. The error is not anException, so nothing catches it and the server process dies on its firstwss://client. This sets thetcp_nodelaystream context option on the listening socket instead, which PHP applies to every accepted connection whether it is encrypted or not, and removes the call that needed the imported socket.Importing the stream also switched off PHP's read buffer as a side effect, which is what kept each read from an accepted connection to the length asked for, and so kept the number of data events the rate limiter counts proportional to the bytes received. The accepted stream is therefore now made unbuffered explicitly. The new tests accept a plain connection and check that both of these took effect, and accept a TLS connection made from a second process.