Преглед изворни кода

Fix hipchat dropping messages, fixes #1116

Jordi Boggiano пре 7 година
родитељ
комит
ee10777821
2 измењених фајлова са 16 додато и 0 уклоњено
  1. 1 0
      CHANGELOG.md
  2. 15 0
      src/Monolog/Handler/HipChatHandler.php

+ 1 - 0
CHANGELOG.md

@@ -12,6 +12,7 @@
   * Dropped official support for HHVM in test builds
   * Fixed normalization of exception traces when call_user_func is used to avoid serializing objects and the data they contain
   * Fixed naming of fields in Slack handler, all field names are now capitalized in all cases
+  * Fixed HipChatHandler bug where slack dropped messages randomly
   * Fixed normalization of objects in Slack handlers
   * Fixed support for PHP7's Throwable in NewRelicHandler
   * Fixed race bug when StreamHandler sometimes incorrectly reported it failed to create a directory

+ 15 - 0
src/Monolog/Handler/HipChatHandler.php

@@ -219,6 +219,21 @@ class HipChatHandler extends SocketHandler
     protected function write(array $record)
     {
         parent::write($record);
+        $this->finalizeWrite();
+    }
+
+    /**
+     * Finalizes the request by reading some bytes and then closing the socket
+     *
+     * If we do not read some but close the socket too early, hipchat sometimes
+     * drops the request entirely.
+     */
+    protected function finalizeWrite()
+    {
+        $res = $this->getResource();
+        if (is_resource($res)) {
+            @fread($res, 2048);
+        }
         $this->closeSocket();
     }