diff --git a/system/Session/Handlers/RedisHandler.php b/system/Session/Handlers/RedisHandler.php index a85a16c68ca5..815e3644984b 100644 --- a/system/Session/Handlers/RedisHandler.php +++ b/system/Session/Handlers/RedisHandler.php @@ -223,7 +223,7 @@ public function close(): bool if (($pingReply === true) || ($pingReply === '+PONG')) { if (isset($this->lockKey)) { - $this->redis->del($this->lockKey); + $this->releaseLock(); } if (! $this->redis->close()) { diff --git a/tests/system/Session/Handlers/Database/RedisHandlerTest.php b/tests/system/Session/Handlers/Database/RedisHandlerTest.php index d7acb0dbf56d..94d17461d243 100644 --- a/tests/system/Session/Handlers/Database/RedisHandlerTest.php +++ b/tests/system/Session/Handlers/Database/RedisHandlerTest.php @@ -168,4 +168,26 @@ public function testGC(): void $handler = $this->getInstance(); $this->assertSame(1, $handler->gc(3600)); } + + /** + * See https://github.com/codeigniter4/CodeIgniter4/issues/7695 + */ + public function testSecondaryReadAfterClose(): void + { + $handler = $this->getInstance(); + $handler->open($this->sessionSavePath, $this->sessionName); + + $expected = <<<'DATA' + __ci_last_regenerate|i:1664607454;_ci_previous_url|s:32:"http://localhost:8080/index.php/";key|s:5:"value"; + DATA; + $this->assertSame($expected, $handler->read('555556b43phsnnf8if6bo33b635e4447')); + + $handler->close(); + + $handler->open($this->sessionSavePath, $this->sessionName); + + $this->assertSame($expected, $handler->read('555556b43phsnnf8if6bo33b635e4447')); + + $handler->close(); + } }