diff options
author | Libor Peltan <libor.peltan@nic.cz> | 2024-11-18 16:43:59 +0100 |
---|---|---|
committer | Libor Peltan <libor.peltan@nic.cz> | 2024-11-18 16:43:59 +0100 |
commit | c825d84b2c0b53b4b64b53bbdf25da6089bb0207 (patch) | |
tree | 2dd4ea70442894e06f83c038627a4bc23f0fd508 | |
parent | doc/operation: mention the use of the force option for overwriting failed backup (diff) | |
parent | knotd: expiration aborts transaction in progress (diff) | |
download | knot-c825d84b2c0b53b4b64b53bbdf25da6089bb0207.tar.xz knot-c825d84b2c0b53b4b64b53bbdf25da6089bb0207.zip |
Merge branch 'expire_abort_transaction' into 'master'
Zone expiration aborts transaction in progress
Closes #929
See merge request knot/knot-dns!1725
-rw-r--r-- | src/knot/events/handlers/expire.c | 7 | ||||
-rw-r--r-- | tests-extra/tests/ctl/expire_abort/data/expire.zone | 5 | ||||
-rw-r--r-- | tests-extra/tests/ctl/expire_abort/test.py | 64 |
3 files changed, 75 insertions, 1 deletions
diff --git a/src/knot/events/handlers/expire.c b/src/knot/events/handlers/expire.c index 5124e4acb..3e8b6f68b 100644 --- a/src/knot/events/handlers/expire.c +++ b/src/knot/events/handlers/expire.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> +/* Copyright (C) 2024 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,6 +32,11 @@ int event_expire(conf_t *conf, zone_t *zone) log_zone_info(zone->name, "zone expired"); synchronize_rcu(); + + pthread_mutex_lock(&zone->cu_lock); + zone_control_clear(zone); + pthread_mutex_unlock(&zone->cu_lock); + knot_sem_wait(&zone->cow_lock); zone_contents_deep_free(expired); knot_sem_post(&zone->cow_lock); diff --git a/tests-extra/tests/ctl/expire_abort/data/expire.zone b/tests-extra/tests/ctl/expire_abort/data/expire.zone new file mode 100644 index 000000000..0b21bd0c8 --- /dev/null +++ b/tests-extra/tests/ctl/expire_abort/data/expire.zone @@ -0,0 +1,5 @@ +$ORIGIN expire. + +@ SOA dns1 hostmaster 2010111201 2 1 4 7200 + NS dns1 +dns1 A 192.0.2.1 diff --git a/tests-extra/tests/ctl/expire_abort/test.py b/tests-extra/tests/ctl/expire_abort/test.py new file mode 100644 index 000000000..c79431336 --- /dev/null +++ b/tests-extra/tests/ctl/expire_abort/test.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 + +'''Test for automatic zone transaction abort when zone expires''' + +from dnstest.libknot import libknot +from dnstest.test import Test +from dnstest.utils import * + +def check_txn(server, zone, is_open): + ctl = libknot.control.KnotCtl() + ctl.connect(os.path.join(slave.dir, "knot.sock")) + + ctl.send_block(cmd="zone-status", zone=zone, flags="B", filters="t") + resp = ctl.receive_block() + if is_open: + isset(resp[zone]["transaction"] == "open", "open transaction") + else: + isset(resp[zone]["transaction"] == "-", "no transaction") + + ctl.send(libknot.control.KnotCtlType.END) + ctl.close() + +def test_expire(master, slave, zone, manual_expiration): + slave.ctl("zone-refresh") + slave.zone_wait(zone) + master.stop() + + slave.ctl("zone-begin expire") + check_txn(slave, zone[0].name, True) + slave.ctl("zone-set expire test TXT test") + + if manual_expiration: + slave.ctl("-f zone-purge +expire expire") + else: + t.sleep(5) + + try: + slave.ctl("zone-commit expire") + set_err("control txn not aborted") + except Exception: + pass + + check_txn(slave, zone[0].name, False) + resp = slave.dig("test.expire", "TXT") + resp.check(rcode="SERVFAIL") + + master.start() + +t = Test() + +master = t.server("knot") +slave = t.server("knot") +zone = t.zone("expire.", storage=".") +t.link(zone, master, slave) + +t.start() + +# Expire manually +test_expire(master, slave, zone, True) + +# Expire by the SOA timer +test_expire(master, slave, zone, False) + +t.end() |