From 289a3146cb7d9f29acf42dcad48cfc3c4853454c Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 19 Sep 2023 13:21:42 +0200 Subject: [PATCH] networkmanager: Debounce unit change handler firewalld_service's `changed` handler is called in bursts, for all the internal systemd property changes like unit start times. These are not interesting for firewall-client, and just lead to lots of duplicated handler calls. Remember the previous unit state, and short-circuit the handler immediately if there is no interesting change. --- pkg/networkmanager/firewall-client.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/networkmanager/firewall-client.js b/pkg/networkmanager/firewall-client.js index b1483bf740e..0a7a848bb5d 100644 --- a/pkg/networkmanager/firewall-client.js +++ b/pkg/networkmanager/firewall-client.js @@ -204,20 +204,24 @@ function initFirewalldDbus() { firewalld_service.addEventListener('changed', () => { const installed = !!firewalld_service.exists; + const is_running = firewalld_service.state === 'running'; + + // we get lots of these events, for internal property changes; filter interesting changes + if (is_running === firewalld_service.prev_running && firewall.installed === installed) + return; + firewall.installed = installed; + firewalld_service.prev_running = is_running; + debug("systemd service changed: exists", firewalld_service.exists, "state", firewalld_service.state, "firewall.enabled:", JSON.stringify(firewall.enabled)); /* HACK: cockpit.dbus() remains dead for non-activatable names, so reinitialize it if the service gets enabled and started * See https://github.com/cockpit-project/cockpit/pull/9125 */ - if (!firewall.enabled && firewalld_service.state == 'running') { + if (!firewall.enabled && is_running) { debug("reinitializing D-Bus connection after unit got started"); initFirewalldDbus(); } - if (firewall.installed == installed) - return; - - firewall.installed = installed; firewall.dispatchEvent('changed'); });