Skip to content

Commit

Permalink
networkmanager: Debounce unit change handler
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martinpitt committed Sep 20, 2023
1 parent c224b30 commit 289a314
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/networkmanager/firewall-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down

0 comments on commit 289a314

Please sign in to comment.