wambo
wambo

Reputation: 77

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.

Upvotes: 0

Views: 4851

Answers (1)

Hury Shen
Hury Shen

Reputation: 15724

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.

enter image description here

Upvotes: 2

Related Questions