Skip to content

Commit 498bc7b

Browse files
committed
Fix hanging promise in emulator download code
1 parent 7acb14e commit 498bc7b

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

packages/auth/src/platform_node/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ import { FetchProvider } from '../core/util/fetch_provider';
3030
import { getDefaultEmulatorHost } from '@firebase/util';
3131

3232
// Initialize the fetch polyfill, the types are slightly off so just cast and hope for the best
33-
FetchProvider.initialize(
34-
fetch,
35-
Headers,
36-
Response
37-
);
33+
FetchProvider.initialize(fetch, Headers, Response);
3834

3935
// First, we set up the various platform-specific features for Node (register
4036
// the version and declare the Node getAuth function)

scripts/emulator-testing/emulators/emulator.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,20 @@ export abstract class Emulator {
6262
(downloadComplete, downloadFailed) => {
6363
fetch(this.binaryUrl)
6464
.then(resp => {
65-
if (resp.status !== 200) {
65+
if (resp.status !== 200 || resp.body === null) {
6666
console.log('Download of emulator failed: ', resp.statusText);
6767
downloadFailed();
68+
} else {
69+
const reader = resp.body.getReader();
70+
reader.read().then(function readChunk({ done, value }): any {
71+
if (done) {
72+
downloadComplete();
73+
} else {
74+
writer.write(value);
75+
return reader.read().then(readChunk);
76+
}
77+
});
6878
}
69-
const reader = resp.body?.getReader();
70-
reader?.read().then(function readChunk({ done, value }): any {
71-
if (done) {
72-
downloadComplete();
73-
} else {
74-
writer.write(value);
75-
return reader.read().then(readChunk);
76-
}
77-
});
7879
})
7980
.catch(e => {
8081
console.log(`Download of emulator failed: ${e}`);

0 commit comments

Comments
 (0)