Gunicorn port is bound but deploy is failing to detect port (python, fast api)

So my python web service (FastAPI) has the following deploy command:

echo $PORT && gunicorn app.main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:$PORT

I keep getting the following output:

==> No open ports detected, continuing to scan...
==> Docs on specifying a port: https://render.com/docs/web-services#port-binding
Matplotlib is building the font cache; this may take a moment.
==> No open ports detected, continuing to scan...
==> Docs on specifying a port: https://render.com/docs/web-services#port-binding
==> Port scan timeout reached, no open ports detected. Bind your service to at least one port. If you don't need to receive traffic on any port, create a background worker instead.
==> Docs on specifying a port: https://render.com/docs/web-services#port-binding
==> Timed out: Port scan timeout reached, no open ports detected. Bind your service to at least one port. If you don't need to receive traffic on any port, create a background worker instead.
==> Common ways to troubleshoot your deploy: https://render.com/docs/troubleshooting-deploys

I tried the following build command variants which did not make any changes:

echo $PORT && gunicorn app.main:app --bind 0.0.0.0:$PORT --workers 4 --worker-class uvicorn.workers.UvicornWorker
echo $PORT && gunicorn app.main:app --bind 0.0.0.0:${PORT:-10000} --workers 4 --worker-class uvicorn.workers.UvicornWorker
echo $PORT && gunicorn app.main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 127.0.0.1:$PORT

The echo $PORT displays the port so I am a bit lost as to why the rest is not working as I copy pasted from an old web service which didn’t face this issue.

Gunicorn version 23.0.0, Uvicorn version 0.34.0, Python version 3.10.11

1 Like

There is one of two problems here, either:

  1. You are overriding $PORT (and maybe the bind address) via a higher precedence value than Command Line options, or;
  2. Start Command variables are not expanded. You could move your configuration into a configuration file instead, so your Start Command is only gunicorn app.main:app

See Configuration Overview — Gunicorn 23.0.0 documentation

No luck unfortunately, I’ll keep trying to sort it out and update here if I have a chance