JoyCodeProxy icon indicating copy to clipboard operation
JoyCodeProxy copied to clipboard

fix(auth): add background janitor to clean up expired QR sessions

Open TuTouPower opened this issue 5 months ago • 0 comments

Summary

  • QR 登录会话(qrSessions map)在用户放弃扫码后不会被清理,长期运行导致内存泄漏
  • 新增后台 janitor goroutine,每分钟扫描并清理超过 TTL(3 分钟)的过期会话
  • janitor 通过 sync.Once 在首次 QRInit() 时懒启动,不增加无 QR 登录时的开销

Changes

  • pkg/auth/jdlogin.go:
    • 新增 qrSessionTTL 和 qrCleanupInterval 常量,消除硬编码的 3*time.Minute
    • 新增 startQRSessionJanitor() 后台清理协程
    • QRInit() 中通过 sync.Once 触发 janitor 启动
    • QRPollStatus() 中使用统一的 qrSessionTTL 常量

Test plan

  • [ ] go build ./... 通过
  • [ ] go vet ./... 通过(已有的 anthropic_test.go vet 错误与本次修改无关)
  • [ ] 启动服务,发起 QR 登录但不扫码,等待 3+ 分钟后确认 session 被自动清理

🤖 Generated with Claude Code

TuTouPower avatar Jun 15 '26 19:06 TuTouPower