HTTP GET to localhost in a container hangs

I have a container image that has two binaries - application and health. The application exposes two endpoints - one for application at and a health check endpoint at localhost:9000/health. These endpoints are created using Fastify. The health binary does a HTTP GET on the health check endpoint and the binary is invoked by the healthcheck.test in the Docker Compose file. The service uses network_mode as host because the application must connect to Kafka on a different host.

The health check never goes through because the health binary hangs. I ran a docker exec -it for the container and ran the health binary in container shell. The command never finishes - it won’t even terminate with a timed out message - just keeps on running. However, on the host where the Docker Compose project is running, if I do a curl http://localhost:9000/health I get a health output correctly.

So, why does the health binary hang?

This is the Compose YAML.

    container_name: payload
    image: username/payload:v0.0.0
      - ./conf/payload.env
    network_mode: "host"
      test: /health
      interval: 2s
      timeout: 1s
      retries: 3
      start_period: 10s

Hard to say anything about a binary that we don’t know. I understand that you used fastify, but without the source code, I don’t know what we could say. To be honest, even if I see the source code, it is likely that doesn’t help much as I don’t hav experience with fastify.

How do you create that binary? Is there anyhting else in the container or only the two binaries you mentioned? Can you show a Dockerfile too?

It was my mistake. The NodeJs code for doing the HTTP GET did not have a req.end().