startserver: check for DNS before starting (#7188)

The servers are invoked such that they have to look up their service
names in DNS in order to bind a port. This means that when consul is
down, they take a long time to start up- they are timing out the query.

In the meantime there are a number of messages about timed out health
checks. This winds up obscuring the real error, so let's do a quick DNS
check at startup and give a more meaningful error.
This commit is contained in:
Jacob Hoffman-Andrews 2023-12-07 20:03:43 -08:00 committed by GitHub
parent a0ce126a0f
commit f8636cc40e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import collections
import os
import shutil
import signal
import socket
import subprocess
import sys
import tempfile
@ -184,6 +185,14 @@ def start(fakeclock):
signal.signal(signal.SIGTERM, lambda _, __: stop())
signal.signal(signal.SIGINT, lambda _, __: stop())
# Check that we can resolve the service names before we try to start any
# services. This prevents a confusing error (timed out health check).
try:
socket.getaddrinfo('publisher1.service.consul', None)
except Exception as e:
print("Error querying DNS. Is consul running? `docker compose ps bconsul`. %s" % (e))
return False
# Start the pebble-challtestsrv first so it can be used to resolve DNS for
# gRPC.
startChallSrv()