-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove connection adapters and move things to middleware #11412
Conversation
- Remove connection adapters from the public API surface (pubternal) and replace the existing adapters with connection middleware. - Updated the tests
@@ -160,24 +159,6 @@ public partial class MinDataRate | |||
public System.TimeSpan GracePeriod { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } | |||
} | |||
} | |||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Adapter.Internal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sebastienros This will break the benchmarks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -281,5 +260,19 @@ private static X509Certificate2 ConvertToX509Certificate2(X509Certificate certif | |||
|
|||
return new X509Certificate2(certificate); | |||
} | |||
|
|||
private class SslDuplexPipe : DuplexPipeStreamAdapter<SslStream> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sebastienros I'd like to run a performance test with this change. It could affect SSL performance.
The node services test exploded but things look good! |
@@ -171,8 +171,7 @@ public async Task BindAsync(AddressBindContext context) | |||
var httpsDefault = ParseAddress(Constants.DefaultServerHttpsAddress, out https); | |||
context.ServerOptions.ApplyEndpointDefaults(httpsDefault); | |||
|
|||
if (httpsDefault.ConnectionAdapters.Any(f => f.IsHttps) | |||
|| httpsDefault.TryUseHttps()) | |||
if (httpsDefault.IsTls || httpsDefault.TryUseHttps()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't this necessary in our last PR? Do we not have anything testing this address strategy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this change, ParseAddress would never return a ListenOptions object with a ConnectionAdapter pre-attached anyway. It looks like httpsDefault.ConnectionAdapters.Any(f => f.IsHttps)
was never tru before and httpsDefault.IsTls
is never true now.
More evidence of this is that the https
out var is completely ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind. I now see the ApplyEndpointDefaults line. My bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was calling UseHttps in the ConfigureEndpointDefaults callback broken before this change?
@@ -86,7 +86,7 @@ internal async Task Execute(KestrelConnection connection) | |||
} | |||
catch (Exception ex) | |||
{ | |||
Log.LogCritical(0, ex, $"{nameof(ConnectionDispatcher)}.{nameof(Execute)}() {connectionContext.ConnectionId}"); | |||
Log.LogError(0, ex, "Unhandled exception while processing {ConnectionId}.", connectionContext.ConnectionId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a critical exception if middleware throws, it's just an error now. Any user code can cause this to happen.
src/Servers/Kestrel/Core/src/Internal/HttpsConnectionMiddleware.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Middleware/Internal/DuplexPipeStreamAdapter.cs
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Middleware/Internal/DuplexPipeStreamAdapter.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Middleware/Internal/LoggingConnectionMiddleware.cs
Outdated
Show resolved
Hide resolved
@@ -509,7 +506,7 @@ public async Task AbortingTheConnectionSendsFIN() | |||
[MemberData(nameof(ConnectionAdapterData))] | |||
public async Task ConnectionClosedTokenFiresOnClientFIN(ListenOptions listenOptions) | |||
{ | |||
var testContext = new TestServiceContext(LoggerFactory); | |||
var testContext = new TestServiceContext(LoggerFactory) { ExpectedConnectionMiddlewareCount = listenOptions._middleware.Count }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove asserting the middleware count? I feel like it's causing a lot of code churn with very little value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should remove it, but let @halter73 decide, he's the one that added it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with removing it. Before it was very unusual to have multiple, so it almost always signified a test bug where a ListenOptions object was being reused.
Now that so many tests add non-HttpConnectionMiddleware, I'm fine with removing it. Just watch out whenever you're writing kestrel tests not to reuse ListenOptions.
All good! Citine/Windows Before:
After:
|
@@ -6,7 +6,6 @@ | |||
using System.Net; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: rename tests
{ | ||
internal sealed class RawStream : Stream | ||
internal class DuplexPipeStream : Stream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You finally renamed it!!! 🎉🎆🎉
/// A helper for wrapping a Stream decorator from an <see cref="IDuplexPipe"/>. | ||
/// </summary> | ||
/// <typeparam name="TStream"></typeparam> | ||
internal class DuplexPipeStreamAdapter<TStream> : DuplexPipeStream, IDuplexPipe where TStream : Stream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we planning to ship something like this in 3.1 in corefx?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've informally spoken to a few people about it.
@@ -125,6 +110,13 @@ internal virtual string GetDisplayName() | |||
|
|||
public override string ToString() => GetDisplayName(); | |||
|
|||
/// <summary> | |||
/// Adds a middleware delegate to the connection pipeline. | |||
/// Configured by the <c>UseHttps()</c> and <see cref="Hosting.ListenOptionsConnectionLoggingExtensions.UseConnectionLogging(ListenOptions)"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no cref for UseHttps()?
- Remove ExpectedMiddlewareCount since everything is middleware now - Renamed everything adapter to middleware - Added a regression test for an https scenario - Don't send client certs for tests that don't expect it
Fixes #11402