From 39adae9aa85edf86f8b4f7cdad9291d484fe5499 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 3 Jul 2011 06:07:50 -0700 Subject: [PATCH] Prevent Phabot from spinning out of control Summary: When the remote closes the connection, phabot goes into a busy loop because of PHP's "nothing should ever be an error" semantics. Instead, detect connection termination. Test Plan: Disabled the "PONG" response in the protocol handler and let freenode disconnect phabot. It spun out of control before, now it detects the issue and exits to await automatic restart. Reviewed By: jungejason Reviewers: codeblock, jungejason, aran, tuomaspelkonen CC: aran, jungejason Differential Revision: 582 --- src/infrastructure/daemon/irc/bot/PhabricatorIRCBot.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/infrastructure/daemon/irc/bot/PhabricatorIRCBot.php b/src/infrastructure/daemon/irc/bot/PhabricatorIRCBot.php index 6cc6ccaaf4..fcd4a16900 100644 --- a/src/infrastructure/daemon/irc/bot/PhabricatorIRCBot.php +++ b/src/infrastructure/daemon/irc/bot/PhabricatorIRCBot.php @@ -130,6 +130,14 @@ final class PhabricatorIRCBot extends PhabricatorDaemon { } if ($read) { + // Test for connection termination; in PHP, fread() off a nonblocking, + // closed socket is empty string. + if (feof($this->socket)) { + // This indicates the connection was terminated on the other side, + // just exit via exception and let the overseer restart us after a + // delay so we can reconnect. + throw new Exception("Remote host closed connection."); + } do { $data = fread($this->socket, 4096); if ($data === false) {