Skip to content

Allow customizing Socket.AcceptAsync() call #34344

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

Closed
kevin-montrose opened this issue Jul 14, 2021 · 3 comments · Fixed by #34458
Closed

Allow customizing Socket.AcceptAsync() call #34344

kevin-montrose opened this issue Jul 14, 2021 · 3 comments · Fixed by #34458
Assignees
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-kestrel
Milestone

Comments

@kevin-montrose
Copy link

kevin-montrose commented Jul 14, 2021

We have an application where it would useful to be able to inspect a Socket after it is accepted, but before any other operations happen on it, in order to determine whether we want to marshal it over to another process to handle.

Currently this is not possible because once accepted in SocketConnectionListener, a Socket is almost immediately wrapped up in a ConnectionContext and read from.

It is important for us to inspect a Socket immediately, as (on Windows) once asynchronous I/O beings moving a Socket to another process will fail (see DuplicateAndClose).

Describe the solution you'd like

Ideally a new option is added to SocketTransportOptions which, similar to CreateBoundListenSocket, allows customizing this Socket-y operation. I'll have a PR sketching this out up shortly. #34345

@shirhatti shirhatti linked a pull request Jul 14, 2021 that will close this issue
@davidfowl davidfowl added the api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews label Jul 14, 2021
@shirhatti
Copy link
Contributor

Do you mind elaborating on your use case? I'm curious on what you plan to use this for?

@kevin-montrose
Copy link
Author

@shirhatti Currently we've got a single process which is accepting requests for multiple domains. Because of some other constraints beyond our control, we have to keep that one process accepting everything but would like to move the connections to separate processes based on the domain the connection is for. We may also chose to serve some portion of the requests in the existing process.

We basically want to be able to swap the _listenSocket.AcceptAsync(...) out for two different implementations:

  • In our existing process, we'll peek at the SNI extension in TLS ClientHello (and maybe roll some dice) and either return the socket (if we want to serve it in the existing in the process) or marshal it across to a new process
  • In the new processes, we'll be reading these marshalled sockets off of some IPC mechanism

In essence we'd be changing where the Sockets are coming from out from under the rest of the socket transport layer, but once they arrive everything else proceeds as normal. There's just no way to do that currently.

@BrennanConroy BrennanConroy added this to the 6.0-rc1 milestone Jul 14, 2021
@mkArtakMSFT mkArtakMSFT removed the api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews label Aug 1, 2021
@davidfowl
Copy link
Member

We reverted this delay change. The new strategy is to make the SocketConnectionFactory available and that is what would be used along with a custom transport on both the incoming side and receiving side.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 11, 2021
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-kestrel
Projects
None yet
7 participants