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

ClientModel: Investigate the feasibility of providing a tester to know whether PipelineResponse.ContentStream has been read #42049

Closed
annelo-msft opened this issue Feb 17, 2024 · 1 comment
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library. System.ClientModel Base Core library
Milestone

Comments

@annelo-msft
Copy link
Member

We have a problem today in System.ClientModel that if PipelineMessage.BufferResponse is set to false, then PipelineResponse.ContentStream can only be read once. This could be a problem if, for example, a pipeline policy were to read from response.ContentStream -- passing the response back to the end-user of a client from a service method would result in the client method caller getting a network stream they could not read from.

This problem appears today in Azure.Core as well, even for buffered responses which exposed the buffered content in a MemoryStream on Response.ContentStream. If anyone reads Response.ContentStream without returning the stream position to 0, subsequent calls to Response.Content will either throw or return empty BinaryData. It has the same problem stated above when the response content is not buffered.

We should investigate whether we can provide a tester to know whether response ContentStream has been read, or whether there is another solution we could use to solve this problem. In the meantime, we may also want to find a way to guarantee that pipeline policies never read from response.ContentStream (could we build a static analyzer for this for clients in our own repo?).

@KrzysztofCwalina, @AlexanderSher FYI -- this is the problem we discussed in the Azure.Core v-team meeting on 02/15/2024.

@annelo-msft annelo-msft added Client This issue points to a problem in the data-plane of the library. Azure.Core CoreGe 🐶 System.ClientModel Base Core library labels Feb 17, 2024
@annelo-msft annelo-msft added this to the 2024-03 milestone Feb 17, 2024
@annelo-msft
Copy link
Member Author

Addressed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library. System.ClientModel Base Core library
Projects
None yet
Development

No branches or pull requests

1 participant