-
Notifications
You must be signed in to change notification settings - Fork 848
fix: 多次打开微软登录弹窗后报错 #5878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: 多次打开微软登录弹窗后报错 #5878
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -30,7 +30,10 @@ | |||||||||||||||
|
|
||||||||||||||||
| import java.io.IOException; | ||||||||||||||||
| import java.security.SecureRandom; | ||||||||||||||||
| import java.util.*; | ||||||||||||||||
| import java.util.Base64; | ||||||||||||||||
| import java.util.HashMap; | ||||||||||||||||
| import java.util.Locale; | ||||||||||||||||
| import java.util.Map; | ||||||||||||||||
| import java.util.concurrent.CompletableFuture; | ||||||||||||||||
| import java.util.concurrent.ExecutionException; | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -167,6 +170,7 @@ public static class Factory implements OAuth.Callback { | |||||||||||||||
| public final EventManager<GrantDeviceCodeEvent> onGrantDeviceCode = new EventManager<>(); | ||||||||||||||||
| public final EventManager<OpenBrowserEvent> onOpenBrowserAuthorizationCode = new EventManager<>(); | ||||||||||||||||
| public final EventManager<OpenBrowserEvent> onOpenBrowserDevice = new EventManager<>(); | ||||||||||||||||
| private OAuthServer server; | ||||||||||||||||
|
|
||||||||||||||||
| @Override | ||||||||||||||||
| public OAuth.Session startServer() throws IOException, AuthenticationException { | ||||||||||||||||
|
|
@@ -177,7 +181,7 @@ public OAuth.Session startServer() throws IOException, AuthenticationException { | |||||||||||||||
| IOException exception = null; | ||||||||||||||||
| for (int port : new int[]{29111, 29112, 29113, 29114, 29115}) { | ||||||||||||||||
| try { | ||||||||||||||||
| OAuthServer server = new OAuthServer(port); | ||||||||||||||||
| server = new OAuthServer(port); | ||||||||||||||||
| server.start(NanoHTTPD.SOCKET_READ_TIMEOUT, true); | ||||||||||||||||
| return server; | ||||||||||||||||
|
Comment on lines
181
to
186
|
||||||||||||||||
| } catch (IOException e) { | ||||||||||||||||
|
|
@@ -207,6 +211,10 @@ public String getClientId() { | |||||||||||||||
| return System.getProperty("hmcl.microsoft.auth.id", | ||||||||||||||||
| JarUtils.getAttribute("hmcl.microsoft.auth.id", "")); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public void stop() { | ||||||||||||||||
| if (server != null) server.stop(); | ||||||||||||||||
|
Comment on lines
+215
to
+216
|
||||||||||||||||
| public void stop() { | |
| if (server != null) server.stop(); | |
| public synchronized void stop() { | |
| if (server != null) { | |
| server.stop(); | |
| server = null; | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,6 +261,7 @@ private void cancelAllTasks() { | |
| } | ||
|
|
||
| private void onCancel() { | ||
| Accounts.OAUTH_CALLBACK.stop(); | ||
| cancelAllTasks(); | ||
| if (cancelCallback != null) cancelCallback.run(); | ||
|
Comment on lines
263
to
266
|
||
| fireEvent(new DialogCloseEvent()); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OAuthServer.Factory.serveris written from the background login task (viastartServer) and read from the JavaFX thread (viastop()on cancel). As-is it’s notvolatile/synchronized, sostop()may not reliably see the latest server instance and the callback port can remain bound. Make access thread-safe (e.g.,volatile+ synchronized stop/start, or anAtomicReferencewithgetAndSet).