From 3b8c6da2235fa2e2495e8d3bfd969687d4008287 Mon Sep 17 00:00:00 2001 From: klsoft-web Date: Tue, 29 Sep 2026 16:10:13 +0300 Subject: [PATCH 1/2] Fix reusing the previous session ID in Session::open() in long-running workers --- CHANGELOG.md | 1 + src/Session.php | 4 +--- tests/SessionTest.php | 13 +++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6af09c2..1a6c2c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Enh #86: Remove `yiisoft/cookies` dependency (@vjik) - Bug #86: `NullSession::getCookieParameters()` now returns proper cookie parameters instead of an empty array (@vjik) +- Bug #25: Fix reusing the previous session ID in `Session::open()` in long-running workers (@klsoft-web) ## 3.0.2 August 26, 2026 diff --git a/src/Session.php b/src/Session.php index c272959..9f43e7e 100644 --- a/src/Session.php +++ b/src/Session.php @@ -92,9 +92,7 @@ public function open(): void return; } - if ($this->sessionId !== null) { - session_id($this->sessionId); - } + session_id($this->sessionId ?? ''); try { session_start($this->options); diff --git a/tests/SessionTest.php b/tests/SessionTest.php index 5cb781a..a33988f 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -94,6 +94,19 @@ public function testRegenerateIdOpensInactiveSession(): void self::assertNotEquals($id, $session->getId()); } + public function testOpenDoesNotReuseIdOfClosedSession(): void + { + $firstSession = new Session(); + $firstSession->open(); + $firstId = $firstSession->getId(); + $firstSession->close(); + + $secondSession = new Session(); + $secondSession->open(); + + self::assertNotSame($firstId, $secondSession->getId()); + } + public function testDiscard(): void { $session = $this->getSession(); From 6317d6e1cf894ec3af84d731e1e896284b438b1a Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Wed, 30 Sep 2026 01:33:05 +0300 Subject: [PATCH 2/2] Fix formatting in CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a6c2c2..113a854 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Enh #86: Remove `yiisoft/cookies` dependency (@vjik) - Bug #86: `NullSession::getCookieParameters()` now returns proper cookie parameters instead of an empty array (@vjik) -- Bug #25: Fix reusing the previous session ID in `Session::open()` in long-running workers (@klsoft-web) +- Bug #25: Fix reusing the previous session ID in `Session::open()` in long-running workers (@klsoft-web) ## 3.0.2 August 26, 2026