Skip to content

Commit

Permalink
Fixes error EADDRNOTAVAIL in portUtils. (#5112)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchenshi committed Oct 12, 2022
1 parent 6eed1c2 commit 42b94d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
17 changes: 15 additions & 2 deletions src/emulator/portUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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", () => {
Expand Down

0 comments on commit 42b94d6

Please sign in to comment.