K
K
keddad2020-07-25 21:35:31
Python
keddad, 2020-07-25 21:35:31

Asyncpg in Docker - why can it crash with a No Route To Host error if there is definitely a route?

There is a group of containers that is raised by a similar file:

version: "3"
services:
  ff_corecomp:
    restart: always
    build: ./corecomp
    depends_on:
      - ff_postgres
  ff_postgres:
    restart: always
    image: "postgres"
    environment:
      - POSTGRES_PASSWORD=pass


ff_corecomp has the following pooling process for asyncpg:
await asyncpg.create_pool(
        dsn="postgres://postgres:[email protected]_postgres:5432/")


Suddenly, the code started to crash on this line. Traceback:
spoiler
File "./utils/db.py", line 13, in init_pool
ff_corecomp_1 | db.pool = await asyncpg.create_pool(
ff_corecomp_1 | File "/usr/local/lib/python3.8/site-packages/asyncpg/pool.py", line 398, in _async__init__
ff_corecomp_1 | await self._initialize()
ff_corecomp_1 | File "/usr/local/lib/python3.8/site-packages/asyncpg/pool.py", line 426, in _initialize
ff_corecomp_1 | await first_ch.connect()
ff_corecomp_1 | File "/usr/local/lib/python3.8/site-packages/asyncpg/pool.py", line 125, in connect
ff_corecomp_1 | self._con = await self._pool._get_new_connection()
ff_corecomp_1 | File "/usr/local/lib/python3.8/site-packages/asyncpg/pool.py", line 468, in _get_new_connection
ff_corecomp_1 | con = await connection.connect(
ff_corecomp_1 | File "/usr/local/lib/python3.8/site-packages/asyncpg/connection.py", line 1668, in connect
ff_corecomp_1 | return await connect_utils._connect(
ff_corecomp_1 | File "/usr/local/lib/python3.8/site-packages/asyncpg/connect_utils.py", line 663, in _connect
ff_corecomp_1 | raise last_error
ff_corecomp_1 | File "/usr/local/lib/python3.8/site-packages/asyncpg/connect_utils.py", line 652, in _connect
ff_corecomp_1 | con = await _connect_addr(
ff_corecomp_1 | File "/usr/local/lib/python3.8/site-packages/asyncpg/connect_utils.py", line 621, in _connect_addr
ff_corecomp_1 | tr, pr = await asyncio.wait_for(
ff_corecomp_1 | File "/usr/local/lib/python3.8/asyncio/tasks.py", line 483, in wait_for
ff_corecomp_1 | return fut.result()
ff_corecomp_1 | File "uvloop/loop.pyx", line 1974, in create_connection
ff_corecomp_1 | File "uvloop/loop.pyx", line 1951, in uvloop.loop.Loop.create_connection
ff_corecomp_1 | OSError: [Errno 113] No route to host


No route to host gave me exactly two ideas: the network inside the docker is routing something incorrectly, or the postges container has not risen.

The first idea disappeared quickly: I opened a shell in the ff_corecomp container, and pings to ff_postgres calmly come from it. The second idea also turned out to be wrong: by the time the ff_corecomp container is launched, postgres already says that it is ready to accept connections. What else could be wrong here?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
keddad, 2020-07-26
@keddad

I didn't quite understand what solved the problem, but it's one of the two options from this question.
Or it was a problem in TUN, and then it helped

sysctl net.bridge.bridge-nf-call-iptables=0
sysctl net.bridge.bridge-nf-call-arptables=0
sysctl net.bridge.bridge-nf-call-ip6tables=0

Or the problem was in firewalld
# Allows container to container communication, the solution to the problem
firewall-cmd --zone=public --add-masquerade --permanent

# standard http & https stuff
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
# + any other port you may need

# reload the firewall
firewall-cmd --reload

In any case, I applied both solutions - everything worked.

S
shurshur, 2020-07-26
@shurshur

You need to describe access from one container to another using links in docker-compose.yml. Now access is cut by the docker.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question