简体   繁体   中英

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

My Azure Function does not work anymore.
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". Otherwise, your function will be idle and fall in sleep(even if your workflow is less than 10 seconds, it may response timeout). You can turn on "Always On" by clicking "Configuration" --> "General settings" in your function app.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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