Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Use localhost by default for the server log socket. #1077

Closed
wants to merge 1 commit into from

Conversation

ChadSikorra
Copy link
Contributor

This fixes the server log on Windows, which is currently causing the dev environment to hang and become unusable:

symfony/symfony#22712

The hostname "0" apparently doesn't work on Windows, but it does on Linux. Though I've honestly never seen "0" used in a connection string before. I figure localhost is the best default route to go. There is still the issue of the ServerLogHandler in the monolog bridge bundle where the underlying issue surfaced.

Basically since "0:9911" was not valid on Windows, the socket was never opened. Yet every time it would attempt to log to the socket again it would go through the same timeout period. Multiply that by all the times that gets called and you'll be waiting a while to get a response...

Even though this change makes the dev environment usable on Windows, the Server Log handler still has a huge performance impact there. It takes almost 6-8x longer for a page to load in the dev environment now.

@@ -27,7 +27,7 @@ monolog:
server_log:
type: server_log
process_psr_3_messages: false
host: 0:9911
host: localhost:9911
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does 0.0.0.0 work on Windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I guess I wasn't sure what the implication of changing it to localhost would be. I'm guessing 0 gets translated to 0.0.0.0 on 'nix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take that back. While it helps the dev environment not hang completely, windows will not write to 0.0.0.0 (rendering the server:log command useless). On Linux does that just mean write to all interfaces/IPs on the specified TCP port in this context?

@ChadSikorra
Copy link
Contributor Author

Also, whatever is decided here, the server:log command will need to be adjusted as well. Currently running that on Windows just throws an exception and the following error message:

Warning: stream_socket_server(): php_network_getaddresses: getaddrinfo failed: No such host is known.

Running it with --host localhost:9911 or --host 127.0.0.1:9911 works. So would 0.0.0.0 in that context I guess.

fabpot added a commit to symfony/symfony that referenced this pull request May 19, 2017
…ikorra)

This PR was merged into the 3.3 branch.

Discussion
----------

Use 0.0.0.0 as the server log command host default.

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

This fixes the `server:log` command on Windows when run with default settings. The current setting `0` has no meaning on Windows, and `0.0.0.0` is the standard "listen on all addresses/interfaces", so should be the most compatible. It works on both Linux and Windows for me this way.

I mentioned this in another PR where the logger config has the same issue on Windows:

symfony/symfony-standard#1077

Commits
-------

3fcc810 Use 0.0.0.0 as the server log host default.
@ChadSikorra
Copy link
Contributor Author

I found an interesting note in the Windows Socket API error codes that even explicitly states that address 0 is not valid for an address to connect/send to:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668.aspx#WSAEADDRNOTAVAIL

Though if you ping 0 from the command line it returns 0.0.0.0. I guess since INADDR_ANY ultimately equals 0 this is some sort of special reserved meaning. Though I cannot find it documented anywhere. But I still think it's an oversight/bug for Linux/Unix networking to even allow a connection to 0.0.0.0 in general, or at the very least something that shouldn't be done.

@fabpot fabpot closed this May 21, 2017
@fabpot
Copy link
Member

fabpot commented May 21, 2017

I think this PR has been automatically closed because I've just removed the master branch. Can you reopen it on 3.3 instead? Thanks.

@ChadSikorra ChadSikorra deleted the server-log-host branch May 21, 2017 17:50
fabpot added a commit that referenced this pull request May 21, 2017
This PR was merged into the 3.3 branch.

Discussion
----------

Use localhost for the server log handler.

See: #1077. Had to create this new PR to target 3.3 specifically.

This is to set the server log handler hostname to something that's resolvable under both Linux and Windows. I'm not sure if this should stick to localhost or 127.0.0.1 (which is used elsewhere, such as the defaults in the parameters file). Being set to 0 on Windows causes a DNS timeout in `stream_socket_client` which there doesn't seem to be any control over.

Commits
-------

8c680c7 Use localhost for the server log handler.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants