Skip to content

Commit e774366

Browse files
committed
HHVM does not appear to raise an error if the remote connection is closed and will never fail the pending write. stream_socket_get_name() appears to be a reliable way to detect the closed remote connection.
1 parent 4d1c2a4 commit e774366

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/Query/TcpTransportExecutor.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,24 +337,28 @@ public function handleWritable()
337337
$written = \fwrite($this->socket, $this->writeBuffer);
338338
}
339339

340-
\restore_error_handler();
341-
342-
// Only report errors if *nothing* could be sent and an error has been raised.
340+
// Only report errors if *nothing* could be sent and an error has been raised, or we are unable to retrieve the remote socket name (connection dead) [HHVM].
343341
// Ignore non-fatal warnings if *some* data could be sent.
344342
// Any hard (permanent) error will fail to send any data at all.
345343
// Sending excessive amounts of data will only flush *some* data and then
346344
// report a temporary error (EAGAIN) which we do not raise here in order
347345
// to keep the stream open for further tries to write.
348346
// Should this turn out to be a permanent error later, it will eventually
349347
// send *nothing* and we can detect this.
350-
if (($written === false || $written === 0) && $errstr !== null) {
351-
$this->closeError(
352-
'Unable to send query to DNS server ' . $this->nameserver . ' (' . $errstr . ')',
353-
$errno
354-
);
355-
return;
348+
if (($written === false || $written === 0)) {
349+
$name = @\stream_socket_get_name($this->socket, true);
350+
if (!is_string($name) || $errstr !== null) {
351+
\restore_error_handler();
352+
$this->closeError(
353+
'Unable to send query to DNS server ' . $this->nameserver . ' (' . $errstr . ')',
354+
$errno
355+
);
356+
return;
357+
}
356358
}
357359

360+
\restore_error_handler();
361+
358362
if (false === $written) {
359363
return;
360364
} elseif (isset($this->writeBuffer[$written])) {

0 commit comments

Comments
 (0)