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

InspectResponseBody stream consumed #501

Open
AndrewZenith opened this issue Dec 30, 2024 · 6 comments
Open

InspectResponseBody stream consumed #501

AndrewZenith opened this issue Dec 30, 2024 · 6 comments
Labels
priority:p1 High priority/Major issue but not blocking or Big percentage of customers affected.Bug SLA <=7days type: bug A broken experience

Comments

@AndrewZenith
Copy link

AndrewZenith commented Dec 30, 2024

InspectResponseBody stream consumed:

The stream was already consumed. It cannot be read again.

   at System.Net.Http.HttpConnectionResponseContent.ConsumeStream()
   at System.Net.Http.HttpConnectionResponseContent.<<SerializeToStreamAsync>g__Impl|6_0>d.MoveNext()
   at System.Net.Http.HttpContent.<LoadIntoBufferAsyncCore>d__63.MoveNext()
   at System.Net.Http.HttpClient.<<SendAsync>g__Core|83_0>d.MoveNext()
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.<GetHttpResponseMessageAsync>d__33.MoveNext()
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.<SendAsync>d__20`1.MoveNext()
   at Webapi.REST.HMRC.CTC5.Customs.Transits.Movements.Departures.DeparturesRequestBuilder.<PostAsDeparturesPostResponseAsync>d__6.MoveNext() in D:\projects\MyCustoms\webapi\REST\HMRC\CTC5\CTCTraders.cs:line 3829
   at webapi.Services.HMRC.CTC5.CTC5ServiceScoped.<SendDeclarationTenant>d__13.MoveNext() in \webapi\Services\HMRC\CTC5\CTC5ServiceScoped.cs:line 175
var bodyInspectionHandlerOption = new BodyInspectionHandlerOption()
{
    InspectRequestBody = true,
    InspectResponseBody = true,
};

I am sending a MemoryStream containing xml content, as per the following in the yaml:

requestBody:
  description: ""
  content:
      application/xml:
          schema:
              title: Body
              type: object
  required: false

bodyInspectionHandlerOption.ResponseBody has a valid readable stream, here is the response message (full):

:status: 202
content-type: application/json
content-length: 387
date: Mon, 30 Dec 2024 18:48:39 GMT
content-security-policy: default-src 'self'
cache-control: no-cache,no-store,max-age=0
strict-transport-security: max-age=31536000;
x-envoy-upstream-service-time: 1070
x-cache: Miss from cloudfront
via: 1.1 becf925bc0f305e6c4ad68e689dcc2ba.cloudfront.net (CloudFront)
x-amz-cf-pop: LHR50-P6
x-amz-cf-id: 1Ews1gpdlnJgbUbd2R1hKcrFztBNHuBmMmkqxwkvvFWBwqMjETjk9Q==

{"_links":{"self":{"href":"/customs/transits/movements/departures/6772eb068fb20ccf"},"messages":{"href":"/customs/transits/movements/departures/6772eb068fb20ccf/messages"},"message":{"href":"/customs/transits/movements/departures/6772eb068fb20ccf/messages/6772eb06b4ba3d3a"}},"departureId":"6772eb068fb20ccf","messageId":"6772eb06b4ba3d3a","boxId":"70033eac-1f1d-4b24-b242-79829a293404"}

The .yaml for the response is as follows:

responses:
  "202":
    description: Accepted
    content:
      application/json:
        schema:
          oneOf:
          - title: Small message submission response
            required:
            - _links
            - departureId
            - messageId
            type: object
            properties:
              _links:
                title: Links
                required:
                - messages
                - self
                type: object
                properties:
                  self:
                    title: Self
                    required:
                    - href
                    type: object
                    properties:
                      href:
                        type: string
                    example:
                      href: /customs/transits/movements/departures/62fb8f33d233578e
                  messages:
                    title: Messages
                    required:
                    - href
                    type: object
                    properties:
                      href:
                        type: string
                    example:
                      href: /customs/transits/movements/departures/62fb8f33d233578e/messages
                example:
                  self:
                    href: /customs/transits/movements/departures/62fb8f33d233578e
                  messages:
                    href: /customs/transits/movements/departures/62fb8f33d233578e/messages
              departureId:
                type: string
              messageId:
                type: string
              boxId:
                type: string
            example:
              _links:
                self:
                  href: /customs/transits/movements/departures/62fb8f33d233578e
                messages:
                  href: /customs/transits/movements/departures/62fb8f33d233578e/messages
                message:
                  href: /customs/transits/movements/departures/62fb8f33d233578e/messages/64fed8accac1fdc4
              departureId: 62fb8f33d233578e
              messageId: 64fed8accac1fdc4
              boxId: b54c2424-955b-496c-bbce-dfb9f57cd797
          - title: Large message (empty payload) response
            required:
            - _links
            - departureId
            - messageId
            - uploadRequest
            type: object
            properties:
              _links:
                title: Links
                required:
                - messages
                - self
                type: object
                properties:
                  self:
                    title: Self
                    required:
                    - href
                    type: object
                    properties:
                      href:
                        type: string
                    example:
                      href: /customs/transits/movements/departures/62fb8f33d233578e
                  messages:
                    title: Messages
                    required:
                    - href
                    type: object
                    properties:
                      href:
                        type: string
                    example:
                      href: /customs/transits/movements/departures/62fb8f33d233578e/messages
                example:
                  self:
                    href: /customs/transits/movements/departures/62fb8f33d233578e
                  messages:
                    href: /customs/transits/movements/departures/62fb8f33d233578e/messages
              departureId:
                type: string
              messageId:
                type: string
              boxId:
                type: string
              uploadRequest:
                title: Upload Details
                required:
                - fields
                - href
                type: object
                properties:
                  href:
                    type: string
                  fields:
                    type: object
                    additionalProperties: true
                additionalProperties: false
                example:
                  href: https://hmrc.gov.uk/upscan/upload-proxy
                  fields:
                    field_a: value a
                    field_b: value b
            example:
              _links:
                self:
                  href: /customs/transits/movements/departures/62fb8f33d233578e
                messages:
                  href: /customs/transits/movements/departures/62fb8f33d233578e/messages
                message:
                  href: /customs/transits/movements/departures/62fb8f33d233578e/messages/64fed8accac1fdc4
              boxId: b54c2424-955b-496c-bbce-dfb9f57cd797
              departureId: 62fb8f33d233578e
              messageId: 64fed8accac1fdc4
              uploadRequest:
                href: https://hmrc.gov.uk/upscan/upload-proxy
                fields:
                  field_a: value a
                  field_b: value b
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Dec 30, 2024
@baywet
Copy link
Member

baywet commented Dec 31, 2024

Hi @AndrewZenith
Thank you for using kiota and for reaching out.

Can you confirm what version of the kiota dependencies are being used please? if not the latest (1.16.1), can you please upgrade and try again?

Can you also try to set InspectRequestBody to false and see if you still reproduce the issue please? I'm fairly confident that the error is caused by the response, but want to make sure we're looking at the right place.

I believe what's missing here is a call to LoadIntoBuffer

I'd like to mention that we're operating with a reduced team at the moment, expect delays in responses, thank you for your patience!

@baywet baywet added type: bug A broken experience priority:p1 High priority/Major issue but not blocking or Big percentage of customers affected.Bug SLA <=7days labels Dec 31, 2024
@baywet baywet moved this from Needs Triage 🔍 to New📃 in Kiota Dec 31, 2024
@AndrewZenith
Copy link
Author

Hi,

I'm running 1.16.1, and with InspectRequestBody set to false I do not get the error.

@AndrewZenith
Copy link
Author

I just noticed that without the error the response object is not populated correctly either.
There are 2 possible response messages dependant on the request made.

response.DeparturesPostResponseMember1 -> null
response.DeparturesPostResponseMember2 -> null

I'll check to see if the response matches the yaml. Wouldn't be the first time it didn't.

@baywet
Copy link
Member

baywet commented Dec 31, 2024

Hi,

I'm running 1.16.1, and with InspectRequestBody set to false I do not get the error.

Interesting, what happens if you set ONLY InspectRequestBody to true (and response to false)? (just checking for sanity here)

@AndrewZenith
Copy link
Author

Oops, my bad - it was InspectResponseBody I set to false. It is definitely when trying to read the response that it fails. It fails when this is set to true.

I had to remove the oneOf and the first schema from the yaml as well as it would not parse the data to the objects, probably due to the missing discriminator warning.

@andrueastman
Copy link
Member

I believe what's missing here is a call to LoadIntoBuffer

+1

@AndrewZenith Out of curiosity any chance you can also share the used runtime when making the call(netfx or NET version)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:p1 High priority/Major issue but not blocking or Big percentage of customers affected.Bug SLA <=7days type: bug A broken experience
Projects
Status: New📃
Development

No branches or pull requests

3 participants