我正在使用Gunicorn的Google Cloud Run中部署一个python应用程序。我的gunicorn和Cloud Run超时都设置为900秒,这也是Cloud Run的超时。奇怪的是,当我调用该函数时,如果应用程序运行时间超过60秒,而不是运行时间少于60秒,我将从Cloud Run中收到502错误。例如,下面的已部署函数引发此错误:
def process_file(request=request):
time.sleep(61)
...
return handle_response()
但是,如果我将睡眠时间更改为40秒:
def process_file(request=request):
time.sleep(40)
...
return handle_response()
没有502错误。我一开始以为该问题是由nginx引起的,默认超时为60秒,但默认情况下nginx似乎未部署在docker或cloud上,因此这似乎不是问题的起因。我的Dockerfile如下:
FROM continuumio/miniconda3
# Install production dependencies.
RUN conda install numpy==1.17.2
RUN conda install xlsxwriter==1.1.2
RUN conda install pandas==0.25.1
RUN conda install -c conda-forge ciso8601
RUN pip install gunicorn flask gevent flask_mail flask-cors pyjwt firebase_admin networkx datefinder google-cloud-pubsub
# Copy local code to the container image.
COPY app.py .
RUN mkdir backend/
COPY backend/ /backend/
# Service must listen to $PORT environment variable.
# This default value facilitates local development.
ENV PORT 8080
# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind 0.0.0.0:$PORT --workers 1 app:app --timeout 900 --log-level debug
我称云运行axios
在前端中,据我所知没有超时,所以我不认为这应该是一个问题。任何帮助表示赞赏,谢谢!
编辑:这是chrome控制台中错误消息的图像-似乎不太有用:
找出问题。我正在将HTTP POST请求发送到Firebase托管域。Firebase托管的域POST请求在60秒后超时(请参阅Firebase托管的Cloud Function在任何需要60s的请求上重试,即使超时> 60s)-解决方案是直接调用Cloud Run url。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句