From 4e4d6e9f81b34ef5c7a1094b454d06ef0314f0f0 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Thu, 2 Mar 2017 16:38:11 -0600 Subject: [PATCH] Unload server when fwrite fails Ignore errors from fwrite caused by disconnected sockets and immediately unload the server. --- lib/DefaultResolver.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/DefaultResolver.php b/lib/DefaultResolver.php index 2c006e2..271dac4 100644 --- a/lib/DefaultResolver.php +++ b/lib/DefaultResolver.php @@ -195,11 +195,11 @@ REGEX; } // Send request - $bytesWritten = \fwrite($server->socket, $requestPacket); - if ($bytesWritten === false || isset($packet[$bytesWritten])) { - throw new ResolutionException( - "Request send failed" - ); + $bytesWritten = @\fwrite($server->socket, $requestPacket); + if ($bytesWritten === false || $bytesWritten === 0 && (!\is_resource($server->socket) || !\feof($server->socket))) { + $exception = new ResolutionException("Request send failed"); + $this->unloadServer($server->id, $exception); + throw $exception; } $promisor = new Deferred; @@ -265,6 +265,7 @@ REGEX; $uri = $this->parseCustomServerUri($options["server"]); } + $promises = []; foreach ($types as $type) { $promises[] = $this->doRequest($uri, $name, $type); }