From ed1d8a626054e1808aeb09d9db2d2e06d3224add Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Sun, 7 Apr 2024 12:48:06 +0200 Subject: [PATCH] Config - fix locking issue when already owning the lock. In most cases we use config locking, the lock is acquired only once, in which case all works as expected. When a controller fetches a lock and passes it on to one of the core controller wrappers which then re-acquires the same lock, the default is to load the config again. Pending data in other models will be flushed in these cases, which is unexpected if we're updating the same config, but a different section. This change only executes the reload when not yet locked by this process. --- src/opnsense/mvc/app/library/OPNsense/Core/Config.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/opnsense/mvc/app/library/OPNsense/Core/Config.php b/src/opnsense/mvc/app/library/OPNsense/Core/Config.php index 1f89fa1c9..30b4bfcd1 100644 --- a/src/opnsense/mvc/app/library/OPNsense/Core/Config.php +++ b/src/opnsense/mvc/app/library/OPNsense/Core/Config.php @@ -414,7 +414,6 @@ class Config extends Singleton { $this->simplexml = null; $this->statusIsValid = false; - // exception handling if (!file_exists($this->config_file)) { throw new ConfigException('file not found'); @@ -781,16 +780,17 @@ class Config extends Singleton /** * lock configuration - * @param boolean $reload reload config from open file handle to enforce synchronicity + * @param boolean $reload reload config from open file handle to enforce synchronicity, when not already locked */ public function lock($reload = true) { if ($this->config_file_handle !== null) { flock($this->config_file_handle, LOCK_EX); - $this->statusIsLocked = true; - if ($reload) { + if ($reload && !$this->statusIsLocked) { + /* Only lock when the exclusive lock wasn't ours yet. */ $this->load(); } + $this->statusIsLocked = true; } return $this; }