From 42b94d69e62edb85d780e8997a724801d8a48041 Mon Sep 17 00:00:00 2001 From: Yuchen Shi Date: Wed, 12 Oct 2022 08:59:17 -0700 Subject: [PATCH] Fixes error `EADDRNOTAVAIL` in portUtils. (#5112) --- CHANGELOG.md | 1 + src/emulator/portUtils.ts | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cb75b84cde..6294d9ace28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ - Fixes issue where errors were not properly propagating when listing backends. (#5071) - Fixes issue where message from `-m` on deploy was not being properly applied. (#5107) +- Fixes error `EADDRNOTAVAIL` when running emulators in Docker. diff --git a/src/emulator/portUtils.ts b/src/emulator/portUtils.ts index 67a2741755e..77d34a0cc29 100644 --- a/src/emulator/portUtils.ts +++ b/src/emulator/portUtils.ts @@ -9,6 +9,7 @@ import { IPV4_UNSPECIFIED, IPV6_UNSPECIFIED, Resolver } from "./dns"; import { Emulators, ListenSpec } from "./types"; import { Constants } from "./constants"; import { EmulatorLogger } from "./emulatorLogger"; +import { logger } from "../logger"; // See: // - https://stackoverflow.com/questions/4313403/why-do-browsers-block-some-ports @@ -127,10 +128,22 @@ export async function checkListenable( dummyServer.once("error", (err) => { dummyServer.removeAllListeners(); const e = err as Error & { code?: string }; - if (e.code === "EADDRINUSE" || e.code === "EACCES") { + if ( + e.code === "EADDRINUSE" || + e.code === "EACCES" || + // Where the address is not bindable (not just the port), e.g. in Docker: + // https://github.com/firebase/firebase-tools/issues/4741#issuecomment-1275318134 + e.code === "EADDRNOTAVAIL" || + e.code === "EINVAL" + ) { resolve(false); } else { - reject(e); + // Other unknown issues -- we'll log a warning and return unavailable. + logger.warn( + `portUtils: Error when trying to check port ${addr.port} (on ${addr.address}): ${e.code}` + ); + logger.warn(e); + resolve(false); } }); dummyServer.once("listening", () => {