Skip to content

修复多次打开微软登录弹窗后报错的问题#5911

Open
Glavo wants to merge 2 commits intoHMCL-dev:mainfrom
Glavo:microsoft-server
Open

修复多次打开微软登录弹窗后报错的问题#5911
Glavo wants to merge 2 commits intoHMCL-dev:mainfrom
Glavo:microsoft-server

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented Apr 4, 2026

No description provided.

@Glavo
Copy link
Copy Markdown
Member Author

Glavo commented Apr 4, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +166 to +169
@Override
public void close() {
stop();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

建议在 close() 方法中调用 future.completeExceptionally。这样可以确保如果会话被外部关闭(例如在 waitFor() 阻塞时),等待的线程能够立即收到异常并退出,而不是无限期阻塞。由于 future 只能被完成一次,这不会影响正常的登录流程。

Suggested change
@Override
public void close() {
stop();
}
@Override
public void close() {
future.completeExceptionally(new AuthenticationException("Session closed"));
stop();
}

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

2 participants