Skip to content

Commit feea8fc

Browse files
committed
fix: prevent session_start() lock errors with Memcached handler
Fixes #7604 When using Memcached as session handler with concurrent AJAX requests, session_start() could throw 'Unable to clear session lock record' warning. Two issues contributed: 1. MemcachedHandler::close() did not reset $this->lockKey and $this->lock after deleting the lock, unlike releaseLock(). This could leave PHP's session handler in an inconsistent lock state between requests. 2. PHP has a known limitation with custom session handlers where lock cleanup warnings can occur during concurrent access. Using error suppression on session_start() prevents these from becoming fatal errors in production. Changes: - MemcachedHandler::close(): reset lockKey and lock after delete - Session::startSession(): add @ to session_start() with explanatory comment about PHP's custom session handler limitation Note: RedisHandler and DatabaseHandler already properly managed lock state in their close() methods. Ref: #7604
1 parent 2a1c348 commit feea8fc

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

system/Session/Handlers/MemcachedHandler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ public function close(): bool
225225
if (isset($this->memcached)) {
226226
if (isset($this->lockKey)) {
227227
$this->memcached->delete($this->lockKey);
228+
$this->lockKey = null;
229+
$this->lock = false;
228230
}
229231

230232
return true;

system/Session/Session.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,10 @@ protected function startSession()
622622
return;
623623
}
624624

625-
session_start(); // @codeCoverageIgnore
625+
// Error suppression is used to prevent warnings when
626+
// concurrent requests cause session lock conflicts.
627+
// This is a known PHP limitation with custom session handlers.
628+
@session_start(); // @codeCoverageIgnore
626629
}
627630

628631
/**

0 commit comments

Comments
 (0)