Skip to content

Conversation

amcasey
Copy link
Member

@amcasey amcasey commented May 3, 2023

Defer search for dev cert until build bind time

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Description

...so that it can occur after IConfiguration is read. (In particular, so that it occurs during AddressBinder.BindAsync which happens strictly after KestrelConfigurationLoader.Load.) This is important in Docker scenarios since the Docker tools use IConfiguration to tell us where the dev cert directory is mounted.# with '#' will be ignored, and an empty message aborts the commit.

Was #46296
Fixes #45801

amcasey added 2 commits May 1, 2023 16:57
...so that it can occur after IConfiguration is read. (In particular, so that it occurs during AddressBinder.BindAsync which happens strictly after KestrelConfigurationLoader.Load.) This is important in Docker scenarios since the Docker tools use IConfiguration to tell us where the dev cert directory is mounted.# with '#' will be ignored, and an empty message aborts the commit.

Was dotnet#46296
Fixes dotnet#45801
@amcasey
Copy link
Member Author

amcasey commented May 3, 2023

The behavior is finalized (subject to approval), but we can't merge this until #48055 is approved and #48054 is merged and adopted by dotnet-monitor or we'll break them again.

@amcasey amcasey added the blocked The work on this issue is blocked due to some dependency label May 3, 2023
var middleware = new HttpsConnectionMiddleware(next, httpsOptions, loggerFactory, metrics);
// Evaluate the HttpsConnectionAdapterOptions, now that the configuration, if any, has been loaded
var httpsOptions = lazyHttpsOptions.Value;
var loggerFactory = listenOptions.KestrelServerOptions.ApplicationServices.GetRequiredService<ILoggerFactory>();
Copy link
Member

Choose a reason for hiding this comment

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

Will these service lookups here have a performance implication?

Copy link
Member

Choose a reason for hiding this comment

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

It could be moved outside of the lambda so it's not happening per connection.

Copy link
Member

Choose a reason for hiding this comment

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

+1. They were outside the lambda before.

Copy link
Member Author

Choose a reason for hiding this comment

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

For my own edification, this is a squeeze-out-every-drop type optimization, right? We're saving a lookup in a (small) dictionary and a null check?

Copy link
Member

Choose a reason for hiding this comment

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

It's a no-need-to-do-duplicate-work cleanup. We don't expect it to have a huge per impact, but there's no reason to do that extra work here, it's no cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Would it be worthwhile to make the variables Lazy so the lookups aren't wasted in HTTP/3-only scenarios?

@amcasey
Copy link
Member Author

amcasey commented May 8, 2023

Will try eagerly loading configuration instead.

@amcasey amcasey closed this May 8, 2023
@amcasey amcasey mentioned this pull request May 8, 2023
4 tasks
amcasey added a commit to amcasey/aspnetcore that referenced this pull request May 12, 2023
So that configuration-based certs will be considered, if necessary.

Largely salvaged from dotnet#48056
Builds on dotnet#48137
Fixes dotnet#45801
amcasey added a commit that referenced this pull request May 17, 2023
So that configuration-based certs will be considered, if necessary.

Largely salvaged from #48056
Builds on #48137
Fixes #45801
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions blocked The work on this issue is blocked due to some dependency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kestrel config behaves differently when set using env vars vs. in-code
4 participants