Skip to content

SslStream should avoid copying read buffer data when it already has another frame to process #49086

Closed

Description

@geoffkizer

The logic in SslStream.ReadAsyncInternal calls ResetReadBuffer whenever it finishes processing the previous decrypted frame and thus needs to decrypt another frame. However, this is unnecessarily aggressive. We should only do this when we are about to actually issue a read against the underlying stream. If we already have a frame buffered, then we won't read and will just process that frame immediately, which means the copy was pointless.

This might be a good reason to use ArrayBuffer here, since it simplifies some of the buffer management.

Related to #49000
Related to #49019

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Mar 3, 2021
  2. ManickaP commented on Mar 4, 2021

    @ManickaP
    Member

    Triage: unless we have concrete complaints about this hitting customers, we might leave it to future. If this proves to be easy we might do it in 6.0.

  3. added this to the Future milestone on Mar 4, 2021
  4. removed
    untriagedNew issue has not been triaged by the area owner
    on Mar 4, 2021
  5. wfurt commented on Mar 4, 2021

    @wfurt
    Member

    the copy is probably there to make sure there is enough room for the data. There may be enough space even with the read as the buffer may be bigger and next frame may have less then maximum size. In the other hand I'm not sure how often this would happen. I'm wondering if it would make sense add some counters so we have better visibility to some of the operations.

  6. self-assigned this
    on Mar 5, 2021
  7. geoffkizer commented on Mar 6, 2021

    @geoffkizer
    ContributorAuthor

    @wfurt if you are optimizing this to decrypt multiple frames in a single read operation (when available), then I think this would just fall out of the work you are already doing.

    That is, we should only copy the read buffer when we run out of frames to process and need to do a read on the underlying stream.

  8. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Mar 17, 2021
  9. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jun 10, 2021
  10. geoffkizer commented on Jun 25, 2021

    @geoffkizer
    ContributorAuthor

    @wfurt I think you fixed this with your recent PR right?

  11. wfurt commented on Jul 1, 2021

    @wfurt
    Member

    fixed with #50815.

  12. modified the milestones: Future, 6.0.0 on Jul 15, 2021
  13. ghost locked as resolved and limited conversation to collaborators on Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions