I am getting the error message below when I run a HTTP Triggered function app on our main slot :
Status: 502 Bad Gateway
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>502 - Web server received an invalid response while acting as a gateway or proxy server.</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;}
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
background-color:#555555;}
#content{margin:0 0 0 2%;position:relative;}
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
-->
</style>
</head>
<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>
But when I tried to create a new slot and function app with the same exact code, it works fine without getting the error above. It seems like there's an issue with our main slot's configuration but I just can't find any resource to point me to it.
Has anyone else encountered this problem? How did you fix it?
After configuring an application gateway, one of the errors that you may see is "Server Error: 502 - Web server received an invalid response while acting as a gateway or proxy server". This error may happen for the following main reasons: NSG, UDR, or Custom DNS is blocking access to backend pool members.
Note: A Gateway might refer to different things in networking and a 502 error is usually not something you can fix, but requires a fix by the web server or the proxies you are trying to get access through.
Server overload: An overloaded server is one of the most common causes of a 502 error. This is where the server has reached its memory capacity, often activated by an unusually high number of visitors trying to access the same website.
I have this problem when I sent object from MongoDB (by Mongoose method: Model.find()) directly to the response.
Claim.find()
.then(claims => {
context.res = {
status: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
body: claims
};
context.done();
})
I must change this body object to:
Claim.find()
.then(claims => {
context.res = {
status: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
body: JSON.parse(JSON.stringify(claims))
};
context.done();
})
I have seen 502 error many times in different situations.
Most times it is my programming mistake/ config issue.
But today it took a lot more time to find this issue, so sharing here.
Issue #1
s3 = new AWS.S3();
AWS.config.loadFromPath(dirName1 + '\\aws-config.json');
s3.listObjectsV2(..);
Here, though the error is at line 1, the issue happens at line 3
Solution is:
AWS.config.loadFromPath(dirName1 + '\\aws-config.json');
s3 = new AWS.S3();
s3.listObjectsV2(..);
That is, after loading the aws config, we need to create s3 new instance variable.
Issue #2
As given here, https://stackoverflow.com/a/39240447/984471, is about writing file to un-accessible directory, while you can write to D:\local\Temp, we can't write other directories like current directory or D:\
Unfortunately, in the above examples and also other instances I had, the Azure function exists without any log in azure function console, so there is need for a lot debugging required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With