Skip to content

Commit 14e8159

Browse files
authored
Merge pull request #5424 from microsoft/bugfix-cancel-login
Fix auth bugs when cancelling login
2 parents 8cf9ee5 + 36e316b commit 14e8159

File tree

1 file changed

+4
-24
lines changed
  • PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/ui

1 file changed

+4
-24
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/ui/SignInWindow.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import com.intellij.openapi.application.ApplicationManager;
99
import com.intellij.openapi.diagnostic.Logger;
10-
import com.intellij.openapi.progress.ProcessCanceledException;
1110
import com.intellij.openapi.progress.ProgressIndicator;
1211
import com.intellij.openapi.progress.ProgressManager;
1312
import com.intellij.openapi.project.Project;
@@ -38,7 +37,6 @@
3837
import org.apache.commons.lang3.StringUtils;
3938
import org.jdesktop.swingx.JXHyperlink;
4039
import org.jetbrains.annotations.Nullable;
41-
import reactor.core.Disposable;
4240
import reactor.core.publisher.Flux;
4341
import reactor.core.publisher.Mono;
4442
import reactor.core.scheduler.Schedulers;
@@ -197,27 +195,9 @@ private AuthMethodDetails doServicePrincipalLogin() {
197195
}
198196

199197
private static AuthMethodDetails checkCanceled(ProgressIndicator indicator, Mono<? extends AuthMethodDetails> mono) {
200-
CompletableFuture<? extends AuthMethodDetails> future = mono.toFuture();
201-
Disposable disposable = Flux.interval(Duration.ofSeconds(1)).map(ts -> {
202-
if (indicator != null) {
203-
indicator.checkCanceled();
204-
}
205-
return 1;
206-
}).onErrorResume(e -> {
207-
if (e instanceof ProcessCanceledException) {
208-
future.cancel(true);
209-
}
210-
return Mono.empty();
211-
}).subscribeOn(Schedulers.boundedElastic()).subscribe();
212-
try {
213-
return future.get();
214-
} catch (CancellationException e) {
215-
return null;
216-
} catch (Throwable e) {
217-
throw new AzureToolkitRuntimeException("Cannot login due to error: " + e.getMessage(), e);
218-
} finally {
219-
disposable.dispose();
220-
}
198+
final Mono<AuthMethodDetails> cancelMono = Flux.interval(Duration.ofSeconds(1)).map(ignore -> indicator.isCanceled())
199+
.any(cancel -> cancel).map(ignore -> new AuthMethodDetails()).subscribeOn(Schedulers.boundedElastic());
200+
return Mono.firstWithSignal(cancelMono, mono.subscribeOn(Schedulers.boundedElastic())).block();
221201
}
222202

223203
@Override
@@ -328,7 +308,7 @@ private synchronized AuthMethodDetails doDeviceLogin() {
328308
ErrorWindow.show(project, ex.getMessage(), SIGN_IN_ERROR);
329309
}
330310
}
331-
return null;
311+
return new AuthMethodDetails();
332312
}
333313

334314
private static AuthMethodDetails fromAccountEntity(AccountEntity entity) {

0 commit comments

Comments
 (0)