'Azure Functions showing successful in logs but returning 503 error in portal test as well as 502 error in Postman
Certain functions in my Azure Functions (Consumption Plan) are running well but other functions in the same app are not running correctly. They are showing success in logs but 502 error in browser / client app / postman
Notably , everything these functions needs to do (update cosmos db, send email ) is working , even the logs show success but there is the following error in the portal test
Error in Azure portal is HTTP response code 503 Service Unavailable
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html
xmlns='http://www.w3.org/1999/xhtml'><head><meta content='text/html;
charset=utf-8' http-equiv='content-type'/><style type='text/css'>
body {font-family:Arial; margin-left:40px; }img { border:0 none; }
#content { margin-left: auto; margin-right: auto }#message h2
{ font-size: 20px; font-weight: normal; color: #000000; margin: 34px 0px 0px 0px }
#message p { font-size: 13px; color: #000000; margin: 7px 0px 0px0px}
#errorref { font-size: 11px; color: #737373; margin-top: 41px }</style>
<title>Service unavailable</title></head><body><div id='content'><div id='message'>
<h2>Our services aren't available right now</h2><p>We're working to restore all
services as soon as possible. Please check back soon.</p></div><div id='errorref'>
Error in Browser / Postman is 502 - Web server received an invalid response while acting as a gateway or proxy server.
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.
What could the problem be? Also, i noticed that functions that run well do not have any code related to sending emails whereas the ones that do not work have code to send email (and the emails are getting sent correctly)
Solution 1:[1]
Please check the below steps if they helps to work around:
Error in Azure portal is HTTP response code 503 Service Unavailable
This situation happens due to network connectivity or service availability issues.
The better approach is to retry the operation and if the issue persists, contact Azure Support as referenced here.
Alternative ways to solve this error is finding the cause by navigating to Diagnose and solve problems to know the root cause of 503 error` as there can be multiple reasons for this error.

Please check the below causes related to 503 error issue if they helps to work around:
- request taking a long time
- application crashing due to an exception.
- average response time is long
- Function App is also an app service so app service enforces limits on the number of outbound connections
Error in Browser / Postman is 502 - Web server received an invalid response while acting as a gateway or proxy server.
As this 502 error, you were addressed in MSFT Q&A.
Normally, 502 error occurs when HTTP is placed instead of HTTPS in the connection but I know that the Azure Functions endpoint look like in this format
http://<APP_NAME>.azurewebsites.net/api/<FUNCTION_NAME>
And 502 error occurs when maximum timeout exceeds the value.
- Please check the timeout value of the function app and the logs, metrics of requestTime, responseTime in Application Insights and if it is the cause, increase the timeout value.
References:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HariKrishnaRajoli-MT |
