Conversation
This branch has not been deployed
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.
Fixes #390. Alternative to #391.
Problem
HttpDriver::handleClient()returns normally in two different situations, andSocketHttpServercan't tell them apart:#391 closes the client in
SocketHttpServer'sfinally, which also covers case 2. As noted in the review there, this breaksamphp/websocket-server. I reproduced it: the handshake completes, and then the client immediately gets1006 ABNORMAL_CLOSE ("Writing to the client failed").Websocket::reapClient()only queues the client handler and returns, so by the timefinallyruns, the server is closing a socket that now belongs to the upgrade handler.Fix
Only the driver knows whether it handed the socket off, so the driver should own the close.
Http2Driveralready does this:shutdown()calls$this->client->close(). OnlyHttp1Driverleaves the client open. This PR makes it consistentwith
Http2Driver:pendingResponse->finally(), so it happens only after the last response has been written and after any upgrade has taken place.upgrade()already closes the client, as before.SocketHttpServerand theHttpDriverinterface are unchanged, so there is no BC break and third-party drivers behave exactly as before.Verification
Scripts against a real server, with
amphp/websocket-serverandamphp/websocket-clientfor the upgrade case:3.x1006)Tests
In
test/Driver/Http1DriverTest.php:testClientClosedWhenConnectionEnds(new): the client is closed when the connection ends normally. Fails on3.x.testUpgradedClientNotClosed(new): the client is not closed after an upgrade. This is the websocket case from Close the client when the HTTP driver returns normally #391.testTimeoutSuspendedDuringRequestHandler(adjusted): it asserted thatclose()is never called. What it actually means to check is that the connection timeout does not close the client while the request handler is running. It now assertsthat
close()is called exactly once, after the handler has finished. Fails on3.x.