Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port 5000 not actually in use #4628

Closed
yeldarby opened this issue Jun 7, 2022 · 3 comments · Fixed by #4643
Closed

Port 5000 not actually in use #4628

yeldarby opened this issue Jun 7, 2022 · 3 comments · Fixed by #4643

Comments

@yeldarby
Copy link
Contributor

yeldarby commented Jun 7, 2022

[REQUIRED] Environment info

firebase-tools: 11.0.1

Platform: macOS 12.3.1

[REQUIRED] Test case

Run firebase serve shortly after killing a previous run of the hosting emulator (and while Google Chrome still has a window open on localhost:5000)

[REQUIRED] Steps to reproduce

firebase serve in cli window, wait for emulator to start up, connect in google chrome, ctrl-c, up arrow, enter in terminal window to restart emulator.

[REQUIRED] Expected behavior

Emulator starts back up on port 5000

[REQUIRED] Actual behavior

Emulator starts on port 5005 with

✔  functions: Using node@16 from host.
⚠  hosting: Port 5000 is not available. Trying another port..

Additional Context

#4415 from @jamesdaniels added checking on OSX for available ports using lsof -i :${port} but this needs to be filtered down to LISTEN connections. Google Chrome shows up in this for a bit after the emulator is terminated with connections in a CLOSED state:

yeldarb@Noctilux ~ % lsof -i:5000       
COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Google    751 yeldarb   33u  IPv4 0x12f202801de3f4f3      0t0  TCP localhost:49958->localhost:commplex-main (CLOSED)
Google    751 yeldarb   44u  IPv4 0x12f202801922ea63      0t0  TCP localhost:49959->localhost:commplex-main (CLOSED)
Google    751 yeldarb   57u  IPv4 0x12f2028019244ab3      0t0  TCP localhost:49960->localhost:commplex-main (CLOSED)

Port 5000 is available to LISTEN in this scenario.

When the emulator is running, the output looks like this instead:

yeldarb@Noctilux ~ % lsof -i:5000
COMMAND     PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Google      751 yeldarb   72u  IPv4 0x12f202801e4d5fd3      0t0  TCP localhost:57279->localhost:avt-profile-2 (ESTABLISHED)
Google      751 yeldarb   73u  IPv4 0x12f202801e4d6a63      0t0  TCP localhost:57280->localhost:avt-profile-2 (ESTABLISHED)
node      37694 yeldarb   29u  IPv4 0x12f202801923b4f3      0t0  TCP localhost:avt-profile-2 (LISTEN)
node      37694 yeldarb   30u  IPv4 0x12f202801e4d4023      0t0  TCP localhost:avt-profile-2->localhost:57279 (ESTABLISHED)
node      37694 yeldarb   53u  IPv4 0x12f202801e4d34f3      0t0  TCP localhost:avt-profile-2->localhost:57280 (ESTABLISHED)

It's really the node process LISTENing on port 5000 that we care about, not the CLOSED connections but the output is just being checked to see if lsof errored, not checking its output for whether the port is actually available or not.

@yeldarby yeldarby added the bug label Jun 7, 2022
@jamesdaniels
Copy link
Member

jamesdaniels commented Jun 7, 2022

Good catch, we could achieve this by appending -sTCP:LISTEN to the lsof check.

The main purpose of this is to actually catch control center's use of port 5000, which Node is not detecting.

@yeldarby
Copy link
Contributor Author

yeldarby commented Jun 8, 2022

Yeah that does appear to work:

yeldarb@Brads-MacBook-Pro app % lsof -i:5000
COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Google    751 yeldarb   40u  IPv4 0x12f2028019229fd3      0t0  TCP localhost:65193->localhost:commplex-main (CLOSED)
Google    751 yeldarb   47u  IPv4 0x12f202801de48023      0t0  TCP localhost:65201->localhost:commplex-main (CLOSED)
yeldarb@Brads-MacBook-Pro app % lsof -i:5000 -sTCP:LISTEN
yeldarb@Brads-MacBook-Pro app % 

@yeldarby
Copy link
Contributor Author

I've been running into this annoyance multiple times per day when switching between different projects so submitted a quick PR to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants