bug #22787 [MonologBridge] Fix the Monlog ServerLogHandler from Hanging on Windows (ChadSikorra)

This PR was squashed before being merged into the 3.3 branch (closes #22787).

Discussion
----------

[MonologBridge] Fix the Monlog ServerLogHandler from Hanging on Windows

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | -
| Fixed tickets | #22712
| License       | MIT

This resolves the issue discussed in https://github.com/symfony/symfony/issues/22712. This works on both Windows and Linux. Specifically it removes the additional hanging that was caused on Windows when attempting to write/close a TCP socket that's not open on the other end in asynchronous mode.

Commits
-------

be60aa401f [MonologBridge] Fix the Monlog ServerLogHandler from Hanging on Windows
This commit is contained in:
Fabien Potencier 2017-05-20 09:30:50 +02:00
commit 159f3c59d5

View File

@ -54,12 +54,12 @@ class ServerLogHandler extends AbstractHandler
$recordFormatted = $this->formatRecord($record);
if (!fwrite($this->socket, $recordFormatted)) {
fclose($this->socket);
if (-1 === stream_socket_sendto($this->socket, $recordFormatted)) {
stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR);
// Let's retry: the persistent connection might just be stale
if ($this->socket = $this->createSocket()) {
fwrite($this->socket, $recordFormatted);
stream_socket_sendto($this->socket, $recordFormatted);
}
}
} finally {