Skip to content

Let abandoned anonymous sessions stop blocking re-login - #31

Merged
TungYenTsai merged 1 commit into
mainfrom
fix/anon-stale-session-lock
Nov 6, 2026
Merged

TungYenTsai merged 1 commit into
mainfrom
fix/anon-stale-session-lock

Conversation

@TungYenTsai

Copy link
Copy Markdown
Collaborator

匿名投票者登入後若未完成投票就關閉瀏覽器,再次以同一密碼登入時會出現「此投票密碼已在其他裝置登入中,請先於原裝置登出後再試」,且無法繼續。

原因:Logins::hasActiveSession() 只檢查原 session 檔是否存在。匿名登入閒置逾時(anon.authTimeout,1800 秒)後,原裝置的登入已失效,但 session 檔要等 PHP GC 才刪除(session.timeout 6 小時、GC 機率 1/1000),因此可能鎖住數小時以上。

修改:原 session 檔最後更新時間在匿名登入閒置逾時內,才視為其他裝置登入中。已登入的投票者每次請求都會更新逾時並寫回 session 檔,所以仍在使用中的登入照常阻擋;放棄的登入在逾時後即可由新裝置登入,舊 session 會由既有的 Anon::afterLogin() 清除。管理端「匿名登入狀態」的手動清除功能不變。

不修改 schema、依賴、投票或計票邏輯。

驗證(dev6,PHP 8.2.35):

  • FormAnonConcurrentLoginTest 4 tests/11 assertions 通過,新增「閒置逾時後可重新登入」及「近期活動仍阻擋」兩案;新案例在修改前的程式上失敗,確認重現問題。
  • LoginsTest 19 tests、AnonTest 11 tests、AnonymityNegativeTest 7 tests 通過。
  • 完整 unit/functional 以本 PR CI 為準。

🤖 Generated with Claude Code

@TungYenTsai
TungYenTsai force-pushed the fix/anon-stale-session-lock branch from 8ece598 to 487b914 Compare November 6, 2026 03:32
A voter who closed the browser before finishing kept the password locked
as "logged in on another device" until the session file was garbage
collected, which can take hours. Treat the other session as active only
while it has been used within the anonymous login idle timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TungYenTsai
TungYenTsai merged commit 89304a9 into main Nov 6, 2026
2 checks passed
@TungYenTsai
TungYenTsai deleted the fix/anon-stale-session-lock branch November 6, 2026 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant