Skip to content

Commit ed1d8a6

Browse files
committed
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.
1 parent 3f5d7f0 commit ed1d8a6

File tree

1 file changed

+4
-4
lines changed
  • src/opnsense/mvc/app/library/OPNsense/Core

1 file changed

+4
-4
lines changed

src/opnsense/mvc/app/library/OPNsense/Core/Config.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ private function load()
414414
{
415415
$this->simplexml = null;
416416
$this->statusIsValid = false;
417-
418417
// exception handling
419418
if (!file_exists($this->config_file)) {
420419
throw new ConfigException('file not found');
@@ -781,16 +780,17 @@ public function __destruct()
781780

782781
/**
783782
* lock configuration
784-
* @param boolean $reload reload config from open file handle to enforce synchronicity
783+
* @param boolean $reload reload config from open file handle to enforce synchronicity, when not already locked
785784
*/
786785
public function lock($reload = true)
787786
{
788787
if ($this->config_file_handle !== null) {
789788
flock($this->config_file_handle, LOCK_EX);
790-
$this->statusIsLocked = true;
791-
if ($reload) {
789+
if ($reload && !$this->statusIsLocked) {
790+
/* Only lock when the exclusive lock wasn't ours yet. */
792791
$this->load();
793792
}
793+
$this->statusIsLocked = true;
794794
}
795795
return $this;
796796
}

0 commit comments

Comments
 (0)