Running a uvicorn server as an internal app and setting host to [::] causes deployment to fail

Hi!

Fly is amazing, thank you so much for making cloud deployments so much easier!

However, I have stumbled across a problem i dont know how to solve.

I’m just testing internal api calls between apps in my personal organisation, so things are still super simple.

I have one app acting as a simple api gateway, the uvicorn server is bound to host 0.0.0.0 and this works great for receivng public traffic from the internet.

the second app - let’s call it upstreamA - is another uvicorn server. i had trouble reaching this with my http requests until i read helpful intel here about not binding uvicorn to 0.0.0.0 but instead the equivalent ipv6 of [::].

When i make this change in the uvicorn docker command, the deployment proceeds but fails a critical check and is then rolled back. But during a small window of time, upstreamA IS reachable and returns reposnses. But when the rollback completes (and reverts to previous 0.0.0.0 uvicorn host) the internal requests once again fail.

here is my docker file for upstreamA:

FROM python:3.11 as requirements-stage

WORKDIR /tmp

RUN pip install poetry

COPY ./pyproject.toml ./poetry.lock* /tmp/

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

FROM python:3.11

WORKDIR /code

COPY --from=requirements-stage /tmp/requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

COPY ./upstreamA /code/upstreamA

CMD [“uvicorn”, “upstreamA.main:api”, “–host”, “::”, “–port”, “8000”]

To confirm, deployments work with host as 0.0.0.0 but fail with “::”. However “::” is the only way i can make upstreamA reachable, as confirmed by the temporary success.

Any help or guidance?

So i swapped out uvicorn for hypercorn using the docker commands:

CMD [“hypercorn”, “upstreamA.main:api”, “–bind", "[::]:8000”]

and this did the trick.

I’ll leave this up for anyone else interested and mark it as solved but i still thinks it’s odd and may merit understanding (likely from my side, but maybe from fly’s?)

cheers all

Probably it’s related to Uvicorn listening on ::1 and not in ::

Nevermid, doesn’t work. Gonna open an issue on Uvicorn to see if they know something about

@Moreno, did you ever get a response to this from the Uvicorn team?

Hi folks,

Run uvicorn on an ipv4 interface only:

uvicorn whatever --host 0.0.0.0 --port 8000

Run uvicorn on an ipv6 interface only:

uvicorn whatever --host '::' --port 8000

Run uvicorn on ipv4 and ipv6 dual-stack (empty string passed to host):

uvicorn whatever --host '' --port 8000

test with:

curl -4 http://localhost:8000
curl -6 http://localhost:8000

I am getting the error below in logs within the container in Fly.io. I ensured that I did not set a host.

Error Logs

20:03:58
[PM05] failed to connect to machine: gave up after 15 attempts (in 8.32163148s)
20:03:58
[PC01] instance refused connection. is your app listening on 0.0.0.0:8080? make sure it is not only listening on 127.0.0.1 (hint: look at your startup logs, servers often print the address they are listening on)