Skip to content

Commit b376c30

Browse files
committed
Ignore HHVM errors when closing connection that is already closing
1 parent 84db06f commit b376c30

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/Connection.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ public function handleClose()
2020
return;
2121
}
2222

23-
// http://chat.stackoverflow.com/transcript/message/7727858#7727858
24-
stream_socket_shutdown($this->stream, STREAM_SHUT_RDWR);
23+
// Try to cleanly shut down socket and ignore any errors in case other
24+
// side already closed. Shutting down may return to blocking mode on
25+
// some legacy versions, so reset to non-blocking just in case before
26+
// continuing to close the socket resource.
27+
@stream_socket_shutdown($this->stream, STREAM_SHUT_RDWR);
2528
stream_set_blocking($this->stream, false);
2629
fclose($this->stream);
2730
}

tests/IntegrationTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ public function gettingEncryptedStuffFromGoogleShouldWorkIfHostIsResolvedFirst()
8181
$this->assertRegExp('#^HTTP/1\.0#', $response);
8282
}
8383

84+
/** @test */
85+
public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork()
86+
{
87+
$loop = new StreamSelectLoop();
88+
$connector = new Connector($loop);
89+
90+
$conn = Block\await($connector->connect('google.com:443'), $loop);
91+
92+
$this->assertContains(':443', $conn->getRemoteAddress());
93+
$this->assertNotEquals('google.com:443', $conn->getRemoteAddress());
94+
95+
$conn->write("GET / HTTP/1.0\r\n\r\n");
96+
97+
$response = Block\await(BufferedSink::createPromise($conn), $loop, self::TIMEOUT);
98+
99+
$this->assertNotRegExp('#^HTTP/1\.0#', $response);
100+
}
101+
84102
/** @test */
85103
public function testConnectingFailsIfDnsUsesInvalidResolver()
86104
{

0 commit comments

Comments
 (0)