Skip to content

System.ClientModel: Provide APIs for message types to transfer dispose ownership of response#41764

Merged
annelo-msft merged 17 commits intoAzure:mainfrom
annelo-msft:core-transfer-response-ownership
Feb 7, 2024
Merged

System.ClientModel: Provide APIs for message types to transfer dispose ownership of response#41764
annelo-msft merged 17 commits intoAzure:mainfrom
annelo-msft:core-transfer-response-ownership

Conversation

@annelo-msft
Copy link
Copy Markdown
Member

@annelo-msft annelo-msft commented Feb 2, 2024

Unblock generator work to generate protocol methods for streaming APIs where message.BufferResponse is set to false. This addresses a problem described by @AlexanderSher in https://gist.github.com/AlexanderSher/df22ed21acaa938a4371c188f0699b11.

To the end-user who calls a protocol method, what happens in the message's Dispose function is an implementation detail they're not aware of. We need to be able to hide this detail and allow the end-user to dispose the network stream by disposing Response -- i.e. we must be able to return an un-disposed Response to the end-user.

This PR adds an ExtractResponse method to PipelineMessage in ClientModel. When the Azure.Core/ClientModel integration occurs, this method will move to Azure.Core's HttpMessage as well, which will newslot it to return Response instead of PipelineResponse.

Protocol methods that implement streaming APIs must now:

  1. Set message.BufferResponse = false
  2. Call message.ExtractResponse prior to returning from the method

Convenience methods that call into these protocol methods should call ExtractResponse on the message if they are able to return the network stream to the end-user such that the end-user is able to dispose it. If the convenience method cannot pass dispose ownership to someone else (e.g. because it throws an exception or does not return the network stream because of the response status code), it should dispose the response itself.

@azure-sdk
Copy link
Copy Markdown
Collaborator

azure-sdk commented Feb 2, 2024

API change check

APIView has identified API level changes in this PR and created following API reviews.

Azure.Core
System.ClientModel

@annelo-msft annelo-msft marked this pull request as ready for review February 2, 2024 23:17
@annelo-msft annelo-msft changed the title Core libraries: Provide APIs for message types to transfer dispose ownership of response System.ClientModel: Provide APIs for message types to transfer dispose ownership of response Feb 7, 2024
@annelo-msft annelo-msft enabled auto-merge (squash) February 7, 2024 22:46
@annelo-msft annelo-msft merged commit 6bc87d8 into Azure:main Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants