Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Warn instead of throw when ignoring IServerAddressesFeature #1312

Merged
merged 1 commit into from
Jan 19, 2017

Conversation

halter73
Copy link
Member

  • Throwing could be too much when IServerAddressesFeature URLs come from VS

@@ -122,7 +122,7 @@ public void Start<TContext>(IHttpApplication<TContext> application)
if (addresses.SingleOrDefault() != "http://localhost:5000")
{
var joined = string.Join(", ", addresses);
throw new NotSupportedException($"Specifying address(es) '{joined}' is incompatible with also configuring endpoint(s) in UseKestrel.");
_logger.LogWarning($"Address(es) '{joined}' were overridden. Binding to endpoints defined in UseKestrel instead.");
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: nameof(UseKestrel)
nit 2: add () after UseKestrel to make it clearer it's referring to the method call

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the wording needs to be a little different. It may be confusing to someone specifying multiple addresses in the feature but only overriding a single one of those in UseKestrel().

Maybe something like "Addresses in UseUrls()/IServerAddressesFeature [pick one] were [are? since it's something that will always happen when using both] overriden by the call to UseKestrel(). Binding to endpoints defined in UseKestrel() instead."

Copy link
Member Author

Choose a reason for hiding this comment

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

Referencing UseUrls() or IServerAddressesFeature is the tricky part. UseUrls() might not be the thing that configured the addresses, and I doubt most ASP.NET Core devs know or care what IServerAddressesFeature is. That's why I just show the addresses that were configured.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense.

{
server.Features.Get<IServerAddressesFeature>().Addresses.Add("http://localhost:5001");
StartDummyApplication(server);
Assert.Equal(1, testLogger.TotalWarningsLogged);
Copy link
Contributor

Choose a reason for hiding this comment

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

Check actual message. Also add more addresses to the feature (or better, make it a theory and have cases for single and multiple addresses).

@@ -122,7 +122,7 @@ public void Start<TContext>(IHttpApplication<TContext> application)
if (addresses.SingleOrDefault() != "http://localhost:5000")
Copy link
Member

Choose a reason for hiding this comment

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

Since you don't throw anymore, remove this default check.

@halter73
Copy link
Member Author

⬆️ 📅

else
else if (!hasListenOptions && !hasServerAddresses)
{
listenOptions.Add(Constants.DefaultListenOptions);
Copy link
Member

Choose a reason for hiding this comment

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

Log?

@halter73 halter73 force-pushed the halter73/warn-addresses branch from 8830a8d to d68471c Compare January 19, 2017 19:31
- Throwing could be too much when IServerAddressesFeature URLs come from VS
- Listen on 127.0.0.1:5000 by default

aspnet/Hosting#917
@halter73 halter73 force-pushed the halter73/warn-addresses branch from d68471c to f32058c Compare January 19, 2017 19:36
@halter73 halter73 merged commit f32058c into dev Jan 19, 2017
@halter73 halter73 deleted the halter73/warn-addresses branch January 19, 2017 19:36
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.

4 participants