mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
feat: add config for lock timeout
This commit is contained in:
parent
e10a67b865
commit
8b867d21fd
@ -99,4 +99,29 @@ class Session extends BaseConfig
|
||||
* DB Group for the database session.
|
||||
*/
|
||||
public ?string $DBGroup = null;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Lock Retry Interval (microseconds)
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is used for RedisHandler.
|
||||
*
|
||||
* Time (microseconds) to wait if lock cannot be acquired.
|
||||
* The default is 100,000 microseconds (= 0.1 seconds).
|
||||
*/
|
||||
public int $lockRetryInterval = 100_000;
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Lock Max Retries
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* This is used for RedisHandler.
|
||||
*
|
||||
* Maximum number of lock acquisition attempts.
|
||||
* The default is 300 times. That is lock timeout is about 30 (0.1 * 300)
|
||||
* seconds.
|
||||
*/
|
||||
public int $lockMaxRetries = 300;
|
||||
}
|
||||
|
@ -63,6 +63,16 @@ class RedisHandler extends BaseHandler
|
||||
*/
|
||||
protected $sessionExpiration = 7200;
|
||||
|
||||
/**
|
||||
* Time (microseconds) to wait if lock cannot be acquired.
|
||||
*/
|
||||
private int $lockRetryInterval = 100_000;
|
||||
|
||||
/**
|
||||
* Maximum number of lock acquisition attempts.
|
||||
*/
|
||||
private int $lockMaxRetries = 300;
|
||||
|
||||
/**
|
||||
* @param string $ipAddress User's IP address
|
||||
*
|
||||
@ -76,6 +86,7 @@ class RedisHandler extends BaseHandler
|
||||
$this->sessionExpiration = ($config->expiration === 0)
|
||||
? (int) ini_get('session.gc_maxlifetime')
|
||||
: $config->expiration;
|
||||
|
||||
// Add sessionCookieName for multiple session cookies.
|
||||
$this->keyPrefix .= $config->cookieName . ':';
|
||||
|
||||
@ -84,6 +95,9 @@ class RedisHandler extends BaseHandler
|
||||
if ($this->matchIP === true) {
|
||||
$this->keyPrefix .= $this->ipAddress . ':';
|
||||
}
|
||||
|
||||
$this->lockRetryInterval = $config->lockWait ?? $this->lockRetryInterval;
|
||||
$this->lockMaxRetries = $config->lockAttempts ?? $this->lockMaxRetries;
|
||||
}
|
||||
|
||||
protected function setSavePath(): void
|
||||
@ -359,14 +373,14 @@ class RedisHandler extends BaseHandler
|
||||
);
|
||||
|
||||
if (! $result) {
|
||||
usleep(100000);
|
||||
usleep($this->lockRetryInterval);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->lockKey = $lockKey;
|
||||
break;
|
||||
} while (++$attempt < 300);
|
||||
} while (++$attempt < $this->lockMaxRetries);
|
||||
|
||||
if ($attempt === 300) {
|
||||
$this->logger->error(
|
||||
|
Loading…
x
Reference in New Issue
Block a user