简体   繁体   English

如何修复 Azure Function 上的此 502 错误?

[英]How do I fix this 502 Error on my Azure Function?

My Azure Function does not work anymore.我的 Azure 功能不再起作用。
I didn't change anything on my code or settings and it suddenly stopped working after one week.我没有对代码或设置进行任何更改,一周后它突然停止工作。


<title>502 - Web server received an invalid response while acting as a gateway or proxy server.</title>


      <h1>Server Error</h1>

    <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.


 log.LogInformation($"Received a Request");
            ConvertMe Converter = new ConvertMe();
            var content = await new StreamReader(req.Body).ReadToEndAsync();
            if (content != null)
            {
                Imagebody imagebody = JsonConvert.DeserializeObject<Imagebody>(content);
                MagickImage _Main = new MagickImage(Convert.FromBase64String(imagebody.image1), MagickFormat.Png);
                MagickImage _Overlay = new MagickImage(Convert.FromBase64String(imagebody.image2), MagickFormat.Png);

                using (MemoryStream memory = new MemoryStream())
                {
                    Converter.ComebineBitmap(_Main, _Overlay).Write(memory, MagickFormat.Png);
                    memory.Position = 0;
                    log.LogInformation($"Result: {Convert.ToBase64String(memory?.ToArray())}");
                    return @"data:image/png;base64," + Convert.ToBase64String(memory?.ToArray());
                }
            }

This is my code which is already working (live).这是我的代码,它已经在工作(实时)。 So I really dont know whats going wrong.所以我真的不知道出了什么问题。

As mentioned by Sajeetharan in comments, if you use app service plan, you need to turn on "Always On".正如 Sajeetharan 在评论中提到的,如果您使用应用服务计划,则需要打开“始终开启”。 Otherwise, your function will be idle and fall in sleep(even if your workflow is less than 10 seconds, it may response timeout).否则,您的函数将处于空闲状态并进入睡眠状态(即使您的工作流少于 10 秒,也可能响应超时)。 You can turn on "Always On" by clicking "Configuration" --> "General settings" in your function app.您可以通过单击功能应用中的“配置”-->“常规设置”来打开“始终开启”。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM