From 8d7035ac630b5eb47b4058b5c2dec811ed2e1f9c Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 1 Jun 2021 19:06:55 +0000 Subject: [PATCH 1/4] [Identity] Attempting to fix odd bug on Windows tests --- sdk/identity/identity/CHANGELOG.md | 2 +- .../identity/src/msal/nodeFlows/msalOpenBrowser.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sdk/identity/identity/CHANGELOG.md b/sdk/identity/identity/CHANGELOG.md index 50e8cc6c11e3..21058c7ba81e 100644 --- a/sdk/identity/identity/CHANGELOG.md +++ b/sdk/identity/identity/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.0.0-beta.4 (Unreleased) - +- Fixed an issue in which `InteractiveBrowserCredential` on Node would sometimes cause the process to hang if there was no browser available. ## 2.0.0-beta.3 (2021-05-12) ### New features diff --git a/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts b/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts index 2b2ab23dbde8..99a99a532c75 100644 --- a/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts +++ b/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts @@ -146,10 +146,7 @@ export class MsalOpenBrowser extends MsalNode { app.on("connection", (socket) => socketToDestroy.push(socket)); const server = stoppable(app); - this.openAuthCodeUrl(scopes).catch((e) => { - cleanup(); - reject(e); - }); + const openPromise = this.openAuthCodeUrl(scopes); function cleanup(): void { if (listen) { @@ -173,6 +170,11 @@ export class MsalOpenBrowser extends MsalNode { reject(new Error("Aborted")); }); } + + openPromise.then().catch((e) => { + cleanup(); + reject(e); + }); }); } From ea039b85cd3da297ff86bf65352a63746fc6addc Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 1 Jun 2021 23:19:49 +0000 Subject: [PATCH 2/4] listening before allowing any throw --- .../src/msal/nodeFlows/msalOpenBrowser.ts | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts b/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts index 99a99a532c75..674bcbec57d9 100644 --- a/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts +++ b/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts @@ -138,15 +138,13 @@ export class MsalOpenBrowser extends MsalNode { cleanup(); }); }; + const app = http.createServer(requestListener); + const server = stoppable(app); const listen = app.listen(this.port, this.hostname, () => this.logger.info(`InteractiveBrowserCredential listening on port ${this.port}!`) ); - app.on("connection", (socket) => socketToDestroy.push(socket)); - const server = stoppable(app); - - const openPromise = this.openAuthCodeUrl(scopes); function cleanup(): void { if (listen) { @@ -163,17 +161,23 @@ export class MsalOpenBrowser extends MsalNode { } } - const abortSignal = options?.abortSignal; - if (abortSignal) { - abortSignal.addEventListener("abort", () => { + app.on("connection", (socket) => socketToDestroy.push(socket)); + + app.on("listening", () => { + const openPromise = this.openAuthCodeUrl(scopes); + + const abortSignal = options?.abortSignal; + if (abortSignal) { + abortSignal.addEventListener("abort", () => { + cleanup(); + reject(new Error("Aborted")); + }); + } + + openPromise.then().catch((e) => { cleanup(); - reject(new Error("Aborted")); + reject(e); }); - } - - openPromise.then().catch((e) => { - cleanup(); - reject(e); }); }); } From bea103eed0a99c53dba863bc91807ae3fc8e1232 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 1 Jun 2021 23:23:52 +0000 Subject: [PATCH 3/4] one less change --- sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts b/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts index 674bcbec57d9..c15b983e4f09 100644 --- a/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts +++ b/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts @@ -176,7 +176,7 @@ export class MsalOpenBrowser extends MsalNode { openPromise.then().catch((e) => { cleanup(); - reject(e); + reject(new Error("Aborted")); }); }); }); From 7014fb8e351dfa9da04b3ef7db0344536a9d6db4 Mon Sep 17 00:00:00 2001 From: Daniel Rodriguez Date: Tue, 1 Jun 2021 23:54:04 +0000 Subject: [PATCH 4/4] just throwing the error we receive --- sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts b/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts index c15b983e4f09..674bcbec57d9 100644 --- a/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts +++ b/sdk/identity/identity/src/msal/nodeFlows/msalOpenBrowser.ts @@ -176,7 +176,7 @@ export class MsalOpenBrowser extends MsalNode { openPromise.then().catch((e) => { cleanup(); - reject(new Error("Aborted")); + reject(e); }); }); });