Don't log stack traces for localhost bind failures.#1238
Conversation
| else | ||
| { | ||
| _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv4 loopback interface."); | ||
| _logger.LogInformation(0, $"Unable to bind to {parsedAddress.ToString()} on the IPv4 loopback interface."); |
There was a problem hiding this comment.
I think this should still be a warning - just don't pass the exception to the log call.
There was a problem hiding this comment.
Warnings should be actionable, this isn't. I'm tempted to downgrade it to debug.
There was a problem hiding this comment.
This warning could very well be actionable if you're not running in a shared hosting environment.
There was a problem hiding this comment.
How does shared hosting make the error any different? It's fatal or it isn't.
Yes we know Azure has one specific issue, but overall we've decided that only failing on one protocol isn't fatal.
There was a problem hiding this comment.
Because if you have full control over the host, you could see why binding to either IPv4 or IPv6 failed and then fix it. Typically it's some OS-level configuration, no?
You could also change "localhost" to "127.0.01" or "[::1]" in UseUrls() if you expect to only bind to one interface.
There was a problem hiding this comment.
Depends on the error. What errors have you seen that we may be hiding here?
| } | ||
| else | ||
| { | ||
| _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv6 loopback interface."); |
There was a problem hiding this comment.
What if the error isn't -4089 EAFNOSUPPORT? Should we special case just that error code and log the exception otherwise? If it is something else, it would be good to know.
There was a problem hiding this comment.
I could include the error code. We don't need the stack trace regardless.
There was a problem hiding this comment.
Yeah I was thinking about that too. We know it's a benign error specifically on Azure, but it's still a potentially legit error in other environments.
There was a problem hiding this comment.
I think the scariest part of the log message is the stack trace. How about logging the exception message only?
There was a problem hiding this comment.
And UvException.Message. That would leave out the stack trace. Sometimes libuv uses different error codes on different platforms, so having the message could be useful.
There was a problem hiding this comment.
Looks like the StatusCode is in the Message, no need to duplicate.
There was a problem hiding this comment.
Unable to bind to http://localhost:27574 on the IPv6 loopback interface. (Error -4089 EAFNOSUPPORT address family not supported)
|
LGTM after it's changed back to a warning. If there was an easy way to force an EAFNOSUPPORT error, I would ask for a test, but I think that's more complicated than it's worth. |
| catch (AggregateException ex) when (ex.InnerException is UvException) | ||
| { | ||
| if ((ex.InnerException as UvException).StatusCode == Constants.EADDRINUSE) | ||
| var uvEx = (UvException)ex.InnerException; |
| { | ||
| _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv4 loopback interface."); | ||
| exceptions.Add(ex.InnerException); | ||
| _logger.LogInformation(0, $"Unable to bind to {parsedAddress.ToString()} on the IPv4 loopback interface. ({uvEx.Message})"); |
There was a problem hiding this comment.
Change to ...interface: ({uvEx.Message}) (i.e. colon instead of period)
| { | ||
| _logger.LogWarning(0, ex, $"Unable to bind to {parsedAddress.ToString()} on the IPv6 loopback interface."); | ||
| exceptions.Add(ex.InnerException); | ||
| _logger.LogInformation(0, $"Unable to bind to {parsedAddress.ToString()} on the IPv6 loopback interface. ({uvEx.Message})"); |
There was a problem hiding this comment.
Change to ...interface: ({uvEx.Message}) (i.e. colon instead of period)
| catch (AggregateException ex) when (ex.InnerException is UvException) | ||
| { | ||
| if ((ex.InnerException as UvException).StatusCode == Constants.EADDRINUSE) | ||
| var uvEx = (UvException)ex.InnerException; |
6c9e55c to
a82270e
Compare
a82270e to
53e5c3d
Compare
#1001
We're getting almost daily hits on this issue. A non-fatal error is being displayed like a fatal error and it distracts users from their real problems. Azure may or may not ever change their implementation.
@muratg @halter73
I also recommend we backport this to 1.0.x and 1.1.x.
Before:
After:
We could add an additional log for real fatal errors on line 185.