Skip to content

Commit 59566f6

Browse files
Fix PHP warnings when session backend exits before returning. (#3109)
Co-authored-by: Fabrizio Balliano <[email protected]>
1 parent d762104 commit 59566f6

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

app/code/core/Mage/Core/Model/Session/Abstract/Varien.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Mage_Core_Model_Session_Abstract_Varien extends Varien_Object
3333
public const VALIDATOR_SESSION_LIFETIME = 'session_lifetime';
3434
public const VALIDATOR_PASSWORD_CREATE_TIMESTAMP = 'password_create_timestamp';
3535
public const SECURE_COOKIE_CHECK_KEY = '_secure_cookie_check';
36+
public const REGISTRY_CONCURRENCY_ERROR = 'concurrent_connections_exceeded';
3637

3738
/** @var bool Flag true if session validator data has already been evaluated */
3839
protected static $isValidated = false;
@@ -71,6 +72,9 @@ public function start($sessionName = null)
7172
/* @var Cm_RedisSession_Model_Session $sessionResource */
7273
$sessionResource = Mage::getSingleton('cm_redissession/session');
7374
$sessionResource->setSaveHandler();
75+
if (method_exists($sessionResource, 'setDieOnError')) {
76+
$sessionResource->setDieOnError(false);
77+
}
7478
break;
7579
case 'user':
7680
// getSessionSavePath represents static function for custom session handler setup
@@ -148,7 +152,20 @@ public function start($sessionName = null)
148152
session_cache_limiter((string)$sessionCacheLimiter);
149153
}
150154

151-
session_start();
155+
// Start session, abort and render error page if it fails
156+
try {
157+
if (session_start() === false) {
158+
throw new Exception('Unable to start session.');
159+
}
160+
} catch (Throwable $e) {
161+
session_abort();
162+
if (Mage::registry(self::REGISTRY_CONCURRENCY_ERROR)) {
163+
require_once Mage::getBaseDir() . DS . 'errors' . DS . '503.php';
164+
die();
165+
} else {
166+
Mage::printException($e);
167+
}
168+
}
152169

153170
Mage::dispatchEvent('session_before_renew_cookie', ['cookie' => $cookie]);
154171

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"ext-soap": "*",
2424
"ext-zlib": "*",
2525
"colinmollenhour/cache-backend-redis": "^1.14",
26-
"colinmollenhour/magento-redis-session": "^3.0",
26+
"colinmollenhour/magento-redis-session": "^3.1",
2727
"cweagans/composer-patches": "^1.7",
2828
"magento-hackathon/magento-composer-installer": "^3.1 || ^2.1 || ^4.0",
2929
"pelago/emogrifier": "^7.0",

composer.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/openmage/docker-compose.yml

+7
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,12 @@ services:
6161
volumes:
6262
- mysql:/var/lib/mysql
6363

64+
redis:
65+
image: redis:6-alpine
66+
command: redis-server --appendonly yes --maxmemory 10m
67+
volumes:
68+
- redis:/data
69+
6470
volumes:
6571
mysql:
72+
redis:

0 commit comments

Comments
 (0)