ClientModel: Investigate the feasibility of providing a tester to know whether PipelineResponse.ContentStream has been read #42049
Labels
Azure.Core
Client
This issue points to a problem in the data-plane of the library.
System.ClientModel
Base Core library
Milestone
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.
The text was updated successfully, but these errors were encountered: