From 0fb3930f65074354697b1739cccc1c8041da8fec Mon Sep 17 00:00:00 2001 From: junejaayush <86770465+junejaayush@users.noreply.github.com> Date: Mon, 24 Mar 2025 18:32:54 +0530 Subject: [PATCH] Session files Lock and unlock handled properly Session locking and unlocking was not not handled properly. it give time out issue when ever any request is already in queue then other request has to wait for the completion on the previous one. --- .../Session/drivers/Session_files_driver.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/system/libraries/Session/drivers/Session_files_driver.php b/system/libraries/Session/drivers/Session_files_driver.php index be0dc9ede07..41ac8c7245c 100644 --- a/system/libraries/Session/drivers/Session_files_driver.php +++ b/system/libraries/Session/drivers/Session_files_driver.php @@ -180,7 +180,7 @@ public function read($session_id) return $this->_failure; } - if (flock($this->_file_handle, LOCK_EX) === FALSE) + if (flock($this->_file_handle, LOCK_SH) === FALSE) { log_message('error', "Session: Unable to obtain lock for file '".$this->_file_path.$session_id."'."); fclose($this->_file_handle); @@ -225,6 +225,7 @@ public function read($session_id) } $this->_fingerprint = md5($session_data); + flock($this->_file_handle, LOCK_UN); return $session_data; } @@ -247,7 +248,13 @@ public function write($session_id, $session_data) { return $this->_failure; } - + if (flock($this->_file_handle, LOCK_EX) === FALSE) + { + log_message('error', "Session: Unable to obtain lock for file '".$this->_file_path.$session_id."'."); + fclose($this->_file_handle); + $this->_file_handle = NULL; + return $this->_failure; + } if ( ! is_resource($this->_file_handle)) { return $this->_failure; @@ -284,6 +291,7 @@ public function write($session_id, $session_data) } $this->_fingerprint = md5($session_data); + flock($this->_file_handle, LOCK_UN); return $this->_success; } @@ -300,7 +308,6 @@ public function close() { if (is_resource($this->_file_handle)) { - flock($this->_file_handle, LOCK_UN); fclose($this->_file_handle); $this->_file_handle = $this->_file_new = $this->_session_id = NULL;