【问题标题】:Bad Gateway 502 - Google App Engine - [CRITICAL] WORKER TIMEOUTBad Gateway 502 - Google App Engine - [CRITICAL] 工作人员超时
【发布时间】:2020-08-27 06:45:30
【问题描述】:

当我遇到 502 Bad Gateway Error (Nginx) 时,我正在通过 Google App Engine 部署我的 Web 应用程序。运行gcloud app logs read 后,我发现错误是:

2020-05-12 00:15:59 默认[20200511t163633] "GET /input/summary" 200

2020-05-12 00:16:38 默认[20200511t163633] [2020-05-12 00:16:38 +0000] [1] [CRITICAL] 工作人员超时 (pid:9)

2020-05-12 00:16:38 默认[20200511t163633] [2020-05-12 00:16:38 +0000] [9] [INFO] 工人退出(pid:9)

2020-05-12 00:16:38 默认[20200511t163633] [2020-05-12 00:16:38 +0000] [15] [INFO] 使用 pid:15 引导工作人员

2020-05-12 00:16:38 默认[20200511t163633] "POST /input/summary" 502

对于那些想知道的人,我的 app.yaml 看起来像这样:

    runtime: custom
    env: flex
    
    runtime_config:
      python_version: 3
    
    resources:
      cpu: 4
      memory_gb: 16
      disk_size_gb: 25
    
    readiness_check:
      app_start_timeout_sec: 900

我的 Dockerfile 看起来像这样:

FROM gcr.io/google-appengine/python

RUN virtualenv /env -p python3.7

ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH

ADD requirements.txt /app/requirements.txt
RUN pip3 install -r /app/requirements.txt

ADD . /app

RUN apt-get update \
    && apt-get install tesseract-ocr -y

EXPOSE 8080
ENTRYPOINT ["gunicorn", "--bind=0.0.0.0:8080", "main:app"]

我正在通过以下方式运行应用程序:

    if __name__ == '__main__':
        app.run(debug=True, host='0.0.0.0', port=8080)

在 localhost 上似乎一切正常,但是当我部署到 Google App Engine 时出现问题。有谁知道问题的根源是什么?提前致谢!

【问题讨论】:

  • 默认情况下,Gunicorn 使用同步工作线程,每个工作线程一次只能处理一个请求。默认情况下,gunicorn 只使用其中一个工人。我建议使用recommended gunicorn configuration 查看 Google 文档。让我知道这是否适合您。

标签: google-app-engine nginx google-cloud-platform gunicorn bad-gateway


【解决方案1】:

是否部署失败?还是部署成功了,但是服务端运行失败了?

如果部署失败,您可能会遇到部署作业必须完成的 10 分钟超时。您可以通过设置本地 gcloud 配置来增加此数量。

gcloud config set app/cloud_build_timeout 1200s

【讨论】:

  • 部署良好。它在网络应用程序中导致其失败的特定功能
  • 哦,我明白了。这些人似乎通过增加 gunicorn 的超时时间来缓解这个问题,将它传递给 arg --timeout 90 stackoverflow.com/questions/10855197/… 该线程的另一个建议是传递 gunicorn --log-level=DEBUG 以尝试获取堆栈跟踪。我注意到你设置了app_start_timeout_sec: 900 是什么促使的?
  • 我不确定app_start_timeout_sec: 900;它用于修复我遇到的一些部署错误。我只记得它必须在 300 到 1800 之间。对于--timeout 90,我是在 app.yaml 中添加一个入口点还是在 Dockerfile 中添加一个入口点?如果在 Dockerfile 中,我将如何格式化它(我是 Dockerfiles 的新手)?
  • 你好像把它加到这一行ENTRYPOINT ["gunicorn", "--bind=0.0.0.0:8080", "main:app", "--timeout=90", "--log-level=DEBUG"]
  • 或者可能是这样(我对 dockerfiles 也不是很熟悉)ENTRYPOINT ["gunicorn", "--bind=0.0.0.0:8080", "main:app", "--timeout 90", "--log-level debug"]
猜你喜欢
  • 2021-03-31
  • 2018-08-06
  • 2016-11-13
  • 1970-01-01
  • 2020-03-20
  • 2021-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多