Skip to content

Add transport selector interface to Kestrel sockets and QUIC transports #44832

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

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Nov 2, 2022

Follow up PR to address comment #44657 (comment)

Note:
An edge case with SocketTransportFactory is it allows the factory method to be customized with SocketTransportOptions.CreateBoundListenSocket.

A custom method creating the socket means potentially any endpoint could work. Inside user code, a custom EndPoint implementation could be changed to an endpoint type supported by sockets. Limiting the endpoints that can be used to only built-in types would be a breaking change because the custom endpoint type would no longer work.

Does anyone do this? Probably not. If someone is using a custom endpoint type to pass in custom values to the factory method, a workaround to this change is to inherit from one of the supported endpoint types, e.g. IPEndPoint, and add new members..

Is it worth calling out this change? I can create a breaking change issue for this situation after .NET 7 ships.

@JamesNK JamesNK changed the title Add selector to sockets and QUIC transports Add transport selector interface to Kestrel sockets and QUIC transports Nov 2, 2022
@@ -40,4 +41,16 @@ public ValueTask<IConnectionListener> BindAsync(EndPoint endpoint, CancellationT
transport.Bind();
return new ValueTask<IConnectionListener>(transport);
}

/// <inheritdoc />
public bool CanBind(EndPoint endpoint)
Copy link
Member Author

Choose a reason for hiding this comment

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

This could be an explicit interface implementation if we don't want it public.

Copy link
Member

Choose a reason for hiding this comment

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

Does anyone do this? Probably not. If someone is using a custom endpoint type to pass in custom values to the factory method, a workaround to this change is to inherit from one of the supported endpoint types, e.g. IPEndPoint, and add new members..

Would another workaround be to make CanBind virtual so they can derive from the transport and override it?

Copy link
Member

Choose a reason for hiding this comment

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

Implementing a new interface on a public type is an API change with or without an explicit interface implementation. It doesn't matter what our PublicAPI.Unshipped.txt files have to say about it.

Personally, I think we should make CanBind fully public. It's not like it adds a lot of clutter to the AIP surface of SocketTransportFactory.

Copy link
Member Author

@JamesNK JamesNK Nov 3, 2022

Choose a reason for hiding this comment

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

Sure, CanBind can stay public.

I don't like making CanBind virtual. Nothing else on this type is designed to be extended with inheritance. For example, the create socket factory method is configured via options as a func. If we want to allow people to customize CanBind, then it should also be a func on the options.

Copy link
Member

Choose a reason for hiding this comment

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

I opened #45035 so we can discuss it in API review. I like it though.

@JamesNK
Copy link
Member Author

JamesNK commented Nov 11, 2022

@Tratcher @halter73 Any more feedback on this PR? I'd like to merge it 🙏

@@ -40,4 +41,16 @@ public ValueTask<IConnectionListener> BindAsync(EndPoint endpoint, CancellationT
transport.Bind();
return new ValueTask<IConnectionListener>(transport);
}

/// <inheritdoc />
public bool CanBind(EndPoint endpoint)
Copy link
Member

Choose a reason for hiding this comment

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

I opened #45035 so we can discuss it in API review. I like it though.

Copy link
Member

@Tratcher Tratcher left a comment

Choose a reason for hiding this comment

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

Looks fine, how do you test it?

@JamesNK
Copy link
Member Author

JamesNK commented Nov 23, 2022

The changed test error in this PR shows it works.

@JamesNK JamesNK merged commit f543e35 into main Dec 9, 2022
@JamesNK JamesNK deleted the jamesnk/add-selector-to-transports branch December 9, 2022 02:12
@ghost ghost added this to the 8.0-preview1 milestone Dec 9, 2022
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants