Skip to content

Support 0 byte reads with SSLStream #37122

Closed

Description

@davidfowl

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

Activity

  1. added
    untriaged
    on May 28, 2020
  2. stephentoub commented on May 28, 2020

    @stephentoub
    Member

    It's tested e.g. here:

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

  3. removed
    untriaged
    on May 28, 2020
  4. added this to the 5.0 milestone on May 28, 2020
  5. added
    test-enhancement
    on May 28, 2020
  6. ghost locked as resolved and limited conversation to collaborators on Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Net.Securitytest-enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions