'gunicorn.errors.HaltServer while deploying to google cloud run for a python application

Here is my dockerfile. I am trying to deploy this image to google cloud run using below two command

1. gcloud builds submit --tag gcr.io/smartshop-292203/data_science --timeout=20h0m0s
2. gcloud run deploy --image gcr.io/smartshop-292203/data_science --platform managed

I am using this reference link

https://cloud.google.com/run/docs/quickstarts/build-and-deploy#python

Dockerfile:

FROM python:3.8

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# update image and install cmake
RUN apt-get update 
RUN apt-get upgrade -y
RUN apt-get install cmake -y
RUN apt-get install libgl1-mesa-glx -y

# Install production dependencies.
RUN pip install -r requirements.txt

# command to run on container start
# CMD [ "python", "./app.py" ] 
# CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
CMD exec gunicorn --bind :8001 --workers 1 --threads 8 --timeout 1500 main:app
# CMD exec gunicorn main:app --bind 0.0.0.0:8080 --worker-class aiohttp.GunicornWebWorker
# CMD exec gunicorn --bind 0.0.0.0:8080 wsgi:main
# CMD ["/bin/bash"]

Errors i am getting:

        "Traceback (most recent call last):
    File "/usr/local/bin/gunicorn", line 8, in <module>
        sys.exit(run())
    File "/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
        WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
    File "/usr/local/lib/python3.8/site-packages/gunicorn/app/base.py", line 228, in run
        super().run()
    File "/usr/local/lib/python3.8/site-packages/gunicorn/app/base.py", line 72, in run
        Arbiter(self).run()
    File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py", line 227, in run
        self.halt()
    File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py", line 342, in halt
        self.stop()
    File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py", line 393, in stop
        time.sleep(0.1)
    File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
        self.reap_workers()
    File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
        raise HaltServer(reason, self.WORKER_BOOT_ERROR)
    gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>"

What will be the issue ? Please have a look



Solution 1:[1]

Try to run gunicorn with --preload. You will see the full stack trace. Seems like something wrong on app creation step.

Also you can deploy you app using: gcloud beta run deploy - deploy

More info https://cloud.google.com/sdk/gcloud/reference/beta/run/deploy.

Solution 2:[2]

I cannot find what causes these errors from your error messages so check "LOGS" on Cloud Run as shown below so that you can find more information and details about what causes these errors.

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nazar
Solution 2 Kai - Kazuya Ito