3

I have 3 services: webapp (app), database (db), and redis (rd) that share the same network. Randomly, both connections to the services (database and redis) hangs about 5 seconds. It's not only when I run my webserver that connects to the database, but even when I browse a link on a web page. At some point it freezes and need to wait for about 5 seconds.

I'm not sure but it looks like the connection is automatically closed at some point and need to be re-established.

I don't know I'm supposed to debug this:

  • Running telnet db 5432 or telnet rd 5432 in my app container will always work instantly.
  • Running docker ps -a in my host machine display this: enter image description here

Here is my docker-compose file:

version: "3"

services:
  app:
    depends_on:
      - db
      - rd
    build:
      context: ..
      dockerfile: .devcontainer/service_app/Dockerfile

    volumes:
      - ..:/workspace:delegated

    # Avoid having the container shut down if the default container command fails or exits
    command: /bin/sh -c "while sleep 1000; do :; done"

  db:
    env_file: service_db/.env.local
    build:
      context: ..
      dockerfile: .devcontainer/service_db/Dockerfile
    volumes:
      - "pgdata:/var/lib/postgresql/data"

  rd:
    image: redis:7
    volumes:
      - "rddata:/data"

volumes:
  pgdata:
  rddata:

I don't understand what could cause this. Thanks.

David Dahan
  • 10,576
  • 11
  • 64
  • 137
  • Check DNS and IPv4/6. Otherwise, assuming it's networking, you'll want to start tracking this with tcpdump at various points along the connection (client, firewalls, destination). – BMitch Jul 04 '22 at 13:00
  • @BMitch when running tcpdump, I can see that absolutely nothing happens when it's hanging. Does it mean the problem could be unrelated to network? – David Dahan Jul 04 '22 at 13:31
  • Maybe, or it could be waiting for a response. There's not enough detail to answer. – BMitch Jul 04 '22 at 16:37
  • Which OS are you using? – ikhvjs Jul 05 '22 at 07:02
  • @ikhvjs host OS: last MacOS - container OS: last Debian – David Dahan Jul 05 '22 at 08:23
  • 1
    I am not sure the reason, but what if you replace `sleep infinity` to `/bin/sh -c "while sleep 1000; do :; done"`? I guess sleep infinity may ultilize the container memory... – ikhvjs Jul 06 '22 at 11:08
  • @ikhvjs Good try but it did not change anything. Question updated. – David Dahan Jul 11 '22 at 16:26

1 Answers1

0

Try to replace your sleep loop with tail -f /dev/null

Slava Kuravsky
  • 2,702
  • 10
  • 16