question

JanMechtel-2219 avatar image
0 Votes"
JanMechtel-2219 asked JanMechtel-2219 commented

C# Azure Function returning 502 Bad Gateway, but no error message in the Streaming Logs or Application Insights Failures

I have a simple Azure Function in C# Script (.csx) that's basically a proxy (receiving requests and forwarding them, then sending back the response).

It works fine except now i started sending requests to an ngrok target. Everything inside the functions works fine, include my log messages.

Except that the application making the call to the function (my application but also Postman for testing) receives a 502 Bad Gateway message.

The odd thing is that these 502 failures do not show up in Application Insights Failures.

How can I investigate more?

C# Azure Function returning 502 Bad Gateway, but no error message in the Streaming Logs or Application Insights Failures.

Update 1: I actually found entries in the Application Insights that show the request was completed successfully 200. Even though that's not the case for postman which receives 502


Update 2: Since i have working request (consumer receives 200) and non-working requests (consumer receives 502). I've tried comparing the headers of the responses.

One difference is that working request have a "Request-Context: appId=cid-v1:59e26eaa-a962-4c9d-a2c1-2541b4ae2e15" <> non-working have "Request-Context: appId=" where appId is empty.

Another difference is that non-working request have a response header "Transfer-Encoding: chunked".

 <body>
  <div id="header">
  <h1>Server Error</h1>
  </div>
  <div id="content">
  <div class="content-container">
  <fieldset>
  <h2>502 - Web server received an invalid response while acting as a gateway or proxy server.</h2>
  <h3>There is a problem with the page you are looking for, and it cannot be displayed. When the Web
  server (while acting as a gateway or proxy) contacted the upstream content server, it received an
  invalid response from the content server.</h3>
  </fieldset>
  </div>
  </div>
 </body>
    
 </html>

azure-functions
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @JanMechtel-2219 , Welcome to Microsoft QnA. Thank you for the question. Could you please provide the details I have asked for via private session.

0 Votes 0 ·

I have been experiencing this as well. My SPA client getting 502 errors from a HTTPTrigger Azure Function and not seeing anything in the Application Insights logs.

0 Votes 0 ·

Update 2: Since i have working request (consumer receives 200) and non-working requests (consumer receives 502). I've tried comparing the headers of the responses.

One difference is that working request have a "Request-Context: appId=cid-v1:59e26eaa-a962-4c9d-a2c1-2541b4ae2e15" <> non-working have "Request-Context: appId=" where appId is empty.

Another difference is that non-working request have a response header "Transfer-Encoding: chunked".

0 Votes 0 ·

Thank you @JanMechtel-2219, I have already checked and highlighted the issue to the product. We are hoping to have an update on this soon.

0 Votes 0 ·

Any update?

0 Votes 0 ·

1 Answer

JayaC-MSFT avatar image
0 Votes"
JayaC-MSFT answered JanMechtel-2219 commented

Hello @JanMechtel-2219, I have discussed this issue with the internal core team. In your case , it is ERROR_HTTP_INVALID_SERVER_RESPONSE 12152 The server response could not be parsed.

Error Messages (Wininet.h) - Win32 apps | Microsoft Docs

A retry of the client request will resolve the issue. However, if you still continue getting the error, I would request you to open a support case with Microsoft Support and share the code with them so that it could be investigated.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm unsure what this means. My Function is not exposed to this error so I can not retry the request.

On the consumer side, I can send the request again but I receive the same response 502.

2 Votes 2 ·