factoriotools / factorio-docker

Factorio headless server in a Docker container
https://hub.docker.com/r/factoriotools/factorio/
MIT License
918 stars 218 forks source link

Possibly a docker issue: "Determining own address has failed" when starting multiple Factorio containers simultaneously. #385

Closed bplein closed 3 years ago

bplein commented 3 years ago

This may be a limitation of Docker, but I'll post it here to get your input.

I run 5 containers of factorio using this project's image, all on the same host. I use docker-compose and pass in the differences to it using environment variables.

If I restart a container individually, all is well. But if I do a mass restart (for example, the image is updated, my cron job sees this and in parallel all 5 get restarted), then the ping pong server picks up the wrong UDP port. The container port expose IS correctly exposed (I can test it with netcat) and the container is listening on the correct port, but ping pong gets confused.

This could be a docker issue. I wanted to see if you've seen this before. Right now I'm looking at having to write code that scrapes the log files after a restart to determine if it came up correctly. If anyone else has ideas on "health check" for factorio containers, that would be helpful!

Anyhow, here's the docker-compose template I use (I read in a file that holds the values for each server... and ${LATEST} is set to the specific version that is latest, not "latest":

docker-compose-template.yml

version: '2.2'
services:
  factorio:
    image: "factoriotools/factorio:${LATEST}"
    mem_limit: 12G
    mem_reservation: 4G
    restart: always
    ports:
     - "${GAME_PORT}:${GAME_PORT}/udp"
     - "${RCON_PORT}:${RCON_PORT}/tcp"
    environment:
      - PORT=${GAME_PORT}
      - RCON_PORT=${RCON_PORT}
      - UPDATE_MODS_ON_START=true
    container_name: "${CONTAINER_NAME}"
    volumes:
     - ./volume:/factorio
     - ../scenarios:/factorio/scenarios
    stdin_open: true
    tty: true
    entrypoint: ["/docker-entrypoint.sh", "--verbose"]
bplein commented 3 years ago

Log file when it's affected:

2.861 Warning ServerRouter.cpp:513: Received own address message reply with conflicting address (got IP ADDR:({XXX.XXX.XXX.XXX:34200}), expected IP ADDR:({XXX.XXX.XXX.XXX:18721}))
2.861 Warning ServerMultiplayerManager.cpp:628: Determining own address has failed. Best guess: IP ADDR:({XXX.XXX.XXX.XXX:18721})
2.861 Verbose MatchingServer.cpp:97: Sending create request for game(4294967295) to matching server
2.862 Info HttpSharedState.cpp:54: Downloading https://multiplayer.factorio.com/create-game
2.929 Info ServerRouter.cpp:519: Own address is IP ADDR:({XXX.XXX.XXX.XXX:18721}) (confirmed by pingpong2)
2.946 Info ServerRouter.cpp:519: Own address is IP ADDR:({XXX.XXX.XXX.XXX:18721}) (confirmed by pingpong4)
3.140 Info MatchingServer.cpp:114: Matching server game `9488901` has been created.
3.147 Info ServerMultiplayerManager.cpp:712: Matching server connection 
bplein commented 3 years ago

My script to restart a container has this code in it:

    docker stop $SERVERNAME
    sleep 2
    docker rm $SERVERNAME
    sleep 2
    docker network rm ${CONTAINER_NAME}_default
    rm volume/saves/*.tmp.zip
    sleep 2
    docker-compose up -d
bplein commented 3 years ago

Let's close this. It has nothing to do with the container image. It looks like a Docker issue, maybe a race condition when I'm starting up many at one time. I've switched to host networking for these containers and it works perfectly and may be a bit more performant as well.