Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces resource management for OAuth sessions by having the Session interface extend AutoCloseable and implementing the close method in OAuthServer. Additionally, the authenticateAuthorizationCode method has been updated to use a try-with-resources block. The review feedback suggests enhancing the close implementation in OAuthServer to include completing the internal future exceptionally, which would prevent potential infinite blocking if the session is closed while a thread is waiting.
| @Override | ||
| public void close() { | ||
| stop(); | ||
| } |
There was a problem hiding this comment.
建议在 close() 方法中调用 future.completeExceptionally。这样可以确保如果会话被外部关闭(例如在 waitFor() 阻塞时),等待的线程能够立即收到异常并退出,而不是无限期阻塞。由于 future 只能被完成一次,这不会影响正常的登录流程。
| @Override | |
| public void close() { | |
| stop(); | |
| } | |
| @Override | |
| public void close() { | |
| future.completeExceptionally(new AuthenticationException("Session closed")); | |
| stop(); | |
| } |
There was a problem hiding this comment.
Pull request overview
该 PR 通过确保 OAuth 本地回调服务器在授权流程结束(无论成功/失败/中断)时都能被正确关闭,来修复“多次打开微软登录弹窗后报错”的问题(常见表现是端口占用或残留 server 状态导致后续登录失败)。
Changes:
- 将授权码流程中的
Session改为 try-with-resources 管理,保证退出流程时自动释放资源 - 让
OAuth.Session继承AutoCloseable并显式要求实现close() - 为
OAuthServer增加close(),在关闭时停止 server 并在未完成时结束等待中的 future
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| HMCLCore/src/main/java/org/jackhuang/hmcl/auth/OAuth.java | 用 try-with-resources 自动关闭回调 Session,并将 Session 约束为可关闭资源以避免泄漏 |
| HMCL/src/main/java/org/jackhuang/hmcl/game/OAuthServer.java | 实现 close():停止本地 HTTP server,并在关闭时终止未完成的等待,减少残留端口/线程带来的后续失败 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No description provided.