From 1b5ba807184edc1b0ef84fdc9a1bf8b55c597420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Wed, 3 Dec 2025 13:51:14 +0100 Subject: [PATCH] Revert session handling changes --- config/packages/framework.yaml | 2 +- config/services.yaml | 9 -- src/Session/GracefulSessionHandler.php | 119 ------------------------- 3 files changed, 1 insertion(+), 129 deletions(-) delete mode 100644 src/Session/GracefulSessionHandler.php diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index bac0368..462bae8 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -5,7 +5,7 @@ framework: # Note that the session will be started ONLY if you read or write from it. session: - handler_id: App\Session\GracefulSessionHandler + handler_id: Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler cookie_secure: auto cookie_samesite: lax cookie_lifetime: 2678400 # integer, lifetime in seconds, 0 means 'valid for the length of the browser session' diff --git a/config/services.yaml b/config/services.yaml index 49aa90f..57ecffa 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -60,15 +60,6 @@ services: - auth: - '%env(REDIS_PASSWORD)%' - # Native file session handler for fallback - Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler: ~ - - # Graceful session handler that falls back to files on Redis outage - App\Session\GracefulSessionHandler: - arguments: - - '@Symfony\Component\HttpFoundation\Session\Storage\Handler\RedisSessionHandler' - - '@Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler' - - '@logger' App\Provider\ArticleProvider: tags: diff --git a/src/Session/GracefulSessionHandler.php b/src/Session/GracefulSessionHandler.php deleted file mode 100644 index cd33219..0000000 --- a/src/Session/GracefulSessionHandler.php +++ /dev/null @@ -1,119 +0,0 @@ -redisHandler = $redisHandler; - $this->fileHandler = $fileHandler; - $this->logger = $logger; - } - - protected function doRead(string $sessionId): string - { - if ($this->useRedis) { - try { - $this->handlerOpened = true; - return $this->redisHandler->read($sessionId); - } catch (\Throwable $e) { - $this->useRedis = false; - $this->logger->warning('Redis session read failed; falling back to files', ['e' => $e->getMessage()]); - } - } - $this->handlerOpened = true; - return $this->fileHandler->read($sessionId); - } - - public function updateTimestamp(string $sessionId, string $data): bool - { - if ($this->useRedis) { - try { - return $this->redisHandler->updateTimestamp($sessionId, $data); - } catch (\Throwable $e) { - $this->useRedis = false; - $this->logger->warning('Redis session touch failed; falling back to files', ['e' => $e->getMessage()]); - } - } - // NativeFileSessionHandler doesn't support updateTimestamp, just return true - return true; - } - - protected function doWrite(string $sessionId, string $data): bool - { - if ($this->useRedis) { - try { - return $this->redisHandler->write($sessionId, $data); - } catch (\Throwable $e) { - $this->useRedis = false; - $this->logger->warning('Redis session write failed; falling back to files', ['e' => $e->getMessage()]); - } - } - return $this->fileHandler->write($sessionId, $data); - } - - protected function doDestroy(string $sessionId): bool - { - if ($this->useRedis) { - try { - return $this->redisHandler->destroy($sessionId); - } catch (\Throwable $e) { - $this->useRedis = false; - $this->logger->warning('Redis session destroy failed; falling back to files', ['e' => $e->getMessage()]); - } - } - return $this->fileHandler->destroy($sessionId); - } - - public function close(): bool - { - if (!$this->handlerOpened) { - return true; - } - - try { - if ($this->useRedis) { - return $this->redisHandler->close(); - } else { - return $this->fileHandler->close(); - } - } catch (\Throwable $e) { - $this->logger->warning('Session close error', ['e' => $e->getMessage()]); - return false; - } finally { - $this->handlerOpened = false; - } - } - - public function gc(int $max_lifetime): int|false - { - if ($this->useRedis) { - try { - return $this->redisHandler->gc($max_lifetime); - } catch (\Throwable $e) { - $this->useRedis = false; - $this->logger->warning('Redis session gc failed; falling back to files', ['e' => $e->getMessage()]); - } - } - return $this->fileHandler->gc($max_lifetime); - } -} - -