Skip to content
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

Support 0 byte reads with SSLStream #37122

Closed
davidfowl opened this issue May 28, 2020 · 2 comments · Fixed by #37128
Closed

Support 0 byte reads with SSLStream #37122

davidfowl opened this issue May 28, 2020 · 2 comments · Fixed by #37128
Labels
area-System.Net.Security test-enhancement Improvements of test source code
Milestone

Comments

@davidfowl
Copy link
Member

Bufferless reads are a technique used in a couple of places in ASP.NET Core to avoid renting memory from the memory pool if there's no data available on the socket; this helps when trying to reduce the memory usage for idle connections for applications that are trying to handle a large number of concurrent connections (like websocket based applications).

0 byte reads are supported by Sockets today and we take advantage of that to support the above scenario. We'd like to do the same for HTTPs based connections, so it would need to also work for SSLStream.

The typical layering looks like this for a WebSocket implemention (roughly):

WS.ReadAync(Buffer) 
    -> US.ReadAync(WSHeaderBuffer)
    -> US.ReadAync(Buffer)
        -> SSlStream.ReadAync(TlsFrameBuffer)
        -> SSlStream.ReadAync(Buffer) 
            -> NetworkStream.ReadAync(Buffer)
                -> Socket.ReadAsync(Buffer)

PS: I haven't tested it but if it just works then we should add test coverage so it doesn't regress.

cc: @stephentoub @wfurt

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Net.Security untriaged New issue has not been triaged by the area owner labels May 28, 2020
@ghost
Copy link

ghost commented May 28, 2020

Tagging subscribers to this area: @dotnet/ncl
Notify danmosemsft if you want to be subscribed.

@stephentoub
Copy link
Member

It's tested e.g. here:

[ConditionalTheory(nameof(WebSocketsSupported)), MemberData(nameof(EchoServers))]
public async Task ZeroByteReceive_CompletesWhenDataAvailable(Uri server)

@davidsh davidsh removed the untriaged New issue has not been triaged by the area owner label May 28, 2020
@davidsh davidsh added this to the 5.0 milestone May 28, 2020
@karelz karelz added the test-enhancement Improvements of test source code label May 28, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Security test-enhancement Improvements of test source code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants