Skip to content

Commit

Permalink
Do a gracefull shutdown of recursor, just like systemd
Browse files Browse the repository at this point in the history
This required some fixes in the dnstap test, as it would spin on the EOF it now gets
  • Loading branch information
omoerbeek committed Feb 10, 2025
1 parent 17b0f36 commit 242c779
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
20 changes: 16 additions & 4 deletions regression-tests.recursor-dnssec/recursortests.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,22 @@ def tearDownAuth(cls):
cls.killProcess(auth);

@classmethod
def tearDownRecursor(cls):
p = cls.killProcess(cls._recursor)
if p.returncode not in (0, -15):
raise AssertionError('Process exited with return code %d' % (p.returncode))
def tearDownRecursor(cls, subdir=None):
# We now kill the recursor in a friendly way, as systemd is doing the same.
if subdir is None:
confdir = os.path.join('configs', cls._confdir)
else:
confdir = os.path.join('configs', cls._confdir, subdir)
dirlist = os.listdir(confdir)
print(dirlist)
rec_controlCmd = [os.environ['RECCONTROL'],
'--config-dir=%s' % confdir,
'--timeout=20',
'quit-nicely']
try:
subprocess.check_output(rec_controlCmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
raise AssertionError('%s failed (%d): %s' % (rec_controlCmd, e.returncode, e.output))

@classmethod
def sendUDPQuery(cls, query, timeout=2.0, decode=True, fwparams=dict()):
Expand Down
3 changes: 3 additions & 0 deletions regression-tests.recursor-dnssec/runtests
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
if pgrep pdns_server; then
echo 'There are (stray?) pdns_servers running that might interfere with these tests!'
fi
if pgrep pdns_recursor; then
echo 'There are (stray?) pdns_recursors running that might interfere with these tests!'
fi

export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

Expand Down
4 changes: 2 additions & 2 deletions regression-tests.recursor-dnssec/test_Flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def sendUDPQuery(cls, query, dnssec_setting, timeout=2.0):
@classmethod
def tearDownClass(cls):
cls.tearDownAuth()
for _, recursor in cls._recursors.items():
for subdir, recursor in cls._recursors.items():
cls._recursor = recursor
cls.tearDownRecursor()
cls.tearDownRecursor(subdir)

def getQueryForSecure(self, flags='', ednsflags=''):
return self.createQuery('ns1.example.', 'A', flags, ednsflags)
Expand Down
8 changes: 3 additions & 5 deletions regression-tests.recursor-dnssec/test_RecDnstap.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,9 @@ def FrameStreamUnixListener(cls, conn, param):
if e.errno in (errno.EBADF, errno.EPIPE):
break
sys.stderr.write("Unexpected socket error %s\n" % str(e))
sys.exit(1)
except exception as e:
except Exception as e:
sys.stderr.write("Unexpected socket error %s\n" % str(e))
sys.exit(1)
break
conn.close()

@classmethod
Expand All @@ -208,8 +207,7 @@ def FrameStreamUnixListenerMain(cls, param):
sock.bind(param.path)
sock.listen(100)
except socket.error as e:
sys.stderr.write("Error binding/listening in the framestream listener: %s\n" % str(e))
sys.exit(1)
raise Exception("Error binding/listening in the framestream listener: %s\n" % str(e))
DNSTapListeners.append(sock)
while True:
try:
Expand Down

0 comments on commit 242c779

Please sign in to comment.