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

Error: TIMEOUT: Port 8080 on localhost was not active within 30000ms #2379

Closed
dave-k opened this issue Jun 17, 2020 · 65 comments
Closed

Error: TIMEOUT: Port 8080 on localhost was not active within 30000ms #2379

dave-k opened this issue Jun 17, 2020 · 65 comments

Comments

@dave-k
Copy link

dave-k commented Jun 17, 2020

firebase-debug.log
Cloud Firestore emulator quickstart
I am getting the Timeout error running the emulators:exec command on an unchanged project.

I tried other ports 8081, 8082 and

$ sudo firebase emulators:exec --only firestore 'npm test'
$ firebase emulators:exec 'npm test'
$ firebase emulators:start

produced the same Timeout error.


./firebase/quickstart-nodejs/firestore-emulator/javascript-quickstart

macOS v 10.15.6

$ firebase --version
8.4.2
$ node --version
v14.4.0
$ 

$ firebase emulators:exec --only firestore 'npm test'
i  emulators: Starting emulators: firestore
i  firestore: Firestore Emulator logging to firestore-debug.log
i  emulators: Shutting down emulators.

Error: TIMEOUT: Port 8080 on localhost was not active within 30000ms
@samtstern
Copy link
Contributor

@dave-k when you say "unchanged project" do you mean this was working before and has since stopped? I haven't seen an error like this on macOS yet, could you try two things:

  1. I don't think anyone on our team is using Node 14 yet, most of us are on 12 or below. Does changing your Node version change anything?
  2. If you change the host for the Firestore emulator to 0.0.0.0 instead of localhost does that change anything? You can set this in firebase.json alongside the port.

@samtstern
Copy link
Contributor

Oh also I'm gonna transfer this issue over to the Firebase CLI repo.

@samtstern samtstern transferred this issue from firebase/quickstart-nodejs Jun 19, 2020
@dave-k
Copy link
Author

dave-k commented Jun 20, 2020

@samtstern Unchanged i.e. no changes made to the tests.

  1. node v10.21.0
  2. host: 0.0.0.0

Same Timeout error: [error] Error: TIMEOUT: Port 8080 on 0.0.0.0 was not active within 30000ms
firebase-debug.log

firebase.json

{
  "firestore": {
    "rules": "firestore.rules"
  },
  "emulators": {
    "firestore": {
      "host": "0.0.0.0",
      "port": 8080
    }
  }
}

package.json

{
  "name": "cloud-firestore-emulator-javascript-quickstart",
  "version": "1.0.2",
  "description": "Cloud Firestore emulator testing",
  "scripts": {
    "format": "prettier --write **/*.js",
    "test": "mocha --timeout=10000"
  },
  "devDependencies": {
    "@firebase/testing": "^0.20.3",
    "mocha": "5.2.0",
    "prettier": "1.15.2"
  }
}

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Jun 20, 2020
@samtstern
Copy link
Contributor

@dave-k thanks for trying hose things ... I am still pretty stumped on this issue.

Could you try running the Firestore emulator JAR directly and see if it works for you:

java -jar ~/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar

The exact version of the jar may vary but you should have a cloud-firestore-emulator-*.jar in that location. You can also pass --port=<number> if you don't want to use 8080.

@samtstern samtstern added Needs: Author Feedback Issues awaiting author feedback and removed Needs: Attention labels Jun 22, 2020
@dave-k
Copy link
Author

dave-k commented Jun 22, 2020

@samtstern

$ java -jar ~/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar
API endpoint: http://localhost:8080
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

   export FIRESTORE_EMULATOR_HOST=localhost:8080

Dev App Server is now running.

@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Jun 22, 2020
@samtstern
Copy link
Contributor

samtstern commented Jun 23, 2020

Thank you for all of your information and patience here. You've been super helpful so far.

So in the debug log I don't see Dev App Server is now running which means for some reason the java command we launch from inside the emulator suite is not running the same as the one you ran for me. Here's the last useful line:

[debug] [2020-06-20T02:42:41.242Z] Starting Firestore Emulator with command {"binary":"java","args":["-Duser.language=en","-jar","/Users/dkennedy/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar","--host","0.0.0.0","--port",8080,"--rules","/Users/dkennedy/project-2/firebase/quickstart-nodejs/firestore-emulator/javascript-quickstart/firestore.rules"],"optionalArgs":["port","webchannel_port","host","rules","functions_emulator","seed_from_export"],"joinArgs":false} {"metadata":{"emulator":{"name":"firestore"},"message":"Starting Firestore Emulator with command {\"binary\":\"java\",\"args\":[\"-Duser.language=en\",\"-jar\",\"/Users/dkennedy/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar\",\"--host\",\"0.0.0.0\",\"--port\",8080,\"--rules\",\"/Users/dkennedy/project-2/firebase/quickstart-nodejs/firestore-emulator/javascript-quickstart/firestore.rules\"],\"optionalArgs\":[\"port\",\"webchannel_port\",\"host\",\"rules\",\"functions_emulator\",\"seed_from_export\"],\"joinArgs\":false}"}}
[info] i  firestore: Firestore Emulator logging to firestore-debug.log {"metadata":{"emulator":{"name":"firestore"},"message":"Firestore Emulator logging to \u001b[1mfirestore-debug.log\u001b[22m"}}
[info] i  emulators: Shutting down emulators. {"metadata":{"emulator":{"name":"hub"},"message":"Shutting down emulators."}}

So the command it's trying to run is:

java -Duser.language=en \
  -jar /Users/dkennedy//.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar \
  --host "0.0.0.0" --port 8080 \
  --rules /Users/dkennedy/project-2/firebase/quickstart-nodejs/firestore-emulator/javascript-quickstart/firestore.rules

I guess the last thing to try here is running that exact command, maybe the rules file is somehow changing the result? Again I apologize for basically blind debugging this, I just can't reproduce this myself.

@dave-k
Copy link
Author

dave-k commented Jun 23, 2020

$ java -Duser.language=en \
>   -jar /Users/dkennedy//.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar \
>   --host "0.0.0.0" --port 8091 \
>   --rules /Users/dkennedy/project-2/firebase/quickstart-nodejs/firestore-emulator/javascript-quickstart/firestore.rules
API endpoint: http://0.0.0.0:8091
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

   export FIRESTORE_EMULATOR_HOST=0.0.0.0:8091

Dev App Server is now running.

@dinvlad
Copy link

dinvlad commented Jul 4, 2020

We have the same issue with cloud-firestore-emulator-v1.11.2.jar. What's weirder, it works on one developer's laptop and not another. Same code, same versions of everything (including Java).

@Ross-Rawlins
Copy link

Ross-Rawlins commented Jul 29, 2020

any news on this? I am getting this issue as well when importing a large data set on start up

@samtstern
Copy link
Contributor

@Ross-Rawlins that sounds like a different issue since nobody above has mentioned import! For the issue above we have not been able to reproduce it ourselves, and we really can't fix an issue we can't reproduce (although we acknowledge that it's a real issue)

@beezital
Copy link

Same issue on my side running MacOS too.
It seems to be related to a networking condition involving java.
I have timed java -jar ~/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.5.jar to be 31 seconds before it succeeds starting. Obviously this is too long when firebase emulators:start times out after 30 seconds.
I have a multi-WAN router establishing multiple network connections on different WANs (works great for standard browsing where fetching can happen in parallel). I have experienced other issues with this setup and involving java.
Workaround
So I tunneled my Mac's Internet access through a VPN and now java -jar ~/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.5.jar starts instantaneously. And so does firebase emulators:start.

@handersonc
Copy link

handersonc commented Aug 31, 2020

Same issue here when I run firebase emulators:start --only firestore --import=./backupfolder

i emulators: Starting emulators: firestore
i firestore: Detected non-emulator Firestore export at backupfolder
i firestore: Importing data from backupfolder/mybackup.overall_export_metadata
i firestore: Firestore Emulator logging to firestore-debug.log
i emulators: Shutting down emulators.
i firestore: Stopping Firestore Emulator
i hub: Stopping emulator hub

Error: TIMEOUT: Port 8080 on localhost was not active within 30000ms

@dracomithril
Copy link

So I was fighting with that thing for some time checking every possibility and the I did

npm install -g firebase-tools

and surprise surprise it started working 🤷 why bits me but maybe it will help someone

@ScottPierce
Copy link

ScottPierce commented Oct 21, 2020

I'm having this same problem in Docker Ubuntu environments trying to run CI tests. This morning, it just kept failing left and right for some reason:

yarn run v1.22.5
$ cd firebase && firebase emulators:exec --only firestore "cd .. && yarn test"
⚠  emulators: You are not currently authenticated so some features may not work correctly. Please run firebase login to authenticate the CLI.
i  emulators: Starting emulators: firestore
i  firestore: Firestore Emulator logging to firestore-debug.log
i  emulators: Shutting down emulators.
i  firestore: Stopping Firestore Emulator
i  hub: Stopping emulator hub

Error: TIMEOUT: Port 8080 on 0.0.0.0 was not active within 30000ms

@dracomithril
Copy link

dracomithril commented Oct 21, 2020

Did you add FIREBASE_TOKEN as env variable as it's mentioned in documentation ?

@ScottPierce
Copy link

@dracomithril I don't think that's necessary to run tests. My current theory is that the computer that was running the build was constrained on resources, creating a slow startup time. We started seeing tests time out also. I reduced the number of parallel builds running on the server at one time, and haven't seen it since.

@dracomithril
Copy link

one probably odd question why

cd firebase && firebase emulators:exec --only firestore "cd .. && yarn test"

and not

"scripts": {
    ...
    "test": "firebase emulators:exec --only firestore jest"
  },

and regarding FIREBASE_TOKEN
You are not currently authenticated so some features may not work correctly. Please run firebase login to authenticate the CLI.
in my case it helped 🤷

@ScottPierce
Copy link

ScottPierce commented Oct 22, 2020

one probably odd question why

Because yarn test is the following script:

nx run-many --all --target=test --parallel --maxParallel 3

The above command is fairly complicated, and instead of duplicating it in multiple places, I'd rather centralize it into one place.

You are not currently authenticated so some features may not work correctly. Please run firebase login to authenticate the CLI.
in my case it helped 🤷

This is unlikely to be the solution. It's likely the issue is still there, and it's just intermittent. I still haven't set that, and yet everything is working for me again because I simply stopped running 2 build tasks at the same time on the machine, and limited it to one. That ensures the emulator starts up faster.

@brennengarland
Copy link

I've been having this same problem the last few days out of the blue. I'm running firebase emulators:start --import=data and the output is:

i  emulators: Starting emulators: auth, functions, firestore, database, hosting
!  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: pubsub
!  Your requested "node" version "10" doesn't match your global version "12"
i  firestore: Importing data from C:\repos\proctr\data\firestore_export\firestore_export.overall_export_metadata
i  firestore: Firestore Emulator logging to firestore-debug.log
i  emulators: Shutting down emulators.
i  functions: Stopping Functions Emulator
i  firestore: Stopping Firestore Emulator
!  Firestore Emulator has exited upon receiving signal: SIGINT
i  hub: Stopping emulator hub

Error: TIMEOUT: Port 8080 on localhost was not active within 30000ms

This problem persists if I change the ports.

@dracomithril
Copy link

@brennengarland did you changed node version?

! Your requested "node" version "10" doesn't match your global version "12"

If yes maybe try to reinstall all packages 🤔

@benedelstein
Copy link

Specifying a host in firebase.json seemed to work for me, but then my firestore-triggered cloud functions were not firing, with the error
WARNING: Failed to publish event to localhost:5001: Connection refused

I downgraded to node 16, removed the host key, and now it works.

@TPXP
Copy link

TPXP commented Nov 4, 2021

Hello there, I'm having a similar issue on MacOS Monterey with Node v17.
Adding the host key to the configuration file fixed the startup, and gave me a possibility for the root cause of the issue. Indeed, I had the following line at the end of the my tests (to generate a firestore rules coverage report)

http.get(`http://localhost:${port}/emulator/v1/projects/${projectId}:ruleCoverage.html`, res => {
 // ...
})

This seems to crash as well ! Here's what I got

Error: connect ECONNREFUSED ::1:8090
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16)
Emitted 'error' event on ClientRequest instance at:
    at Socket.socketErrorListener (node:_http_client:447:9)
    at Socket.emit (node:events:390:28)
    at emitErrorNT (node:internal/streams/destroy:164:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 8090
}

Replacing localhost by 127.0.0.1 fixed it, but I think localhost now resolves to ::1(IPv6) instead of 127.0.0.1 (IPv4). Maybe that's why the CLI thinks the emulator is not yet ready

Potentially linked to firebase/firebase-tools-ui#332

@stansotn
Copy link

stansotn commented Nov 6, 2021

I tried numerous things mentioned above suffering from the issue described by OP. The only working solution for me was to downgrade to node 16 (from 17). I'm on Monterey 12.0.1 x86; firebase-tools 9.22.0 .

brew install node@16

# Relink node 17 executable to node 16
ln -sf /usr/local/Cellar/node@16/16.13.0/bin/node /usr/local/bin/node

@evkalinin
Copy link

As @stansotn mentioned, downgrade to 16 node work for me too. Catalina (10.15.7), tools - 9.22.0

brew unlink node
brew install node@16
brew link --overwrite node@16

@jangruenwaldt
Copy link

As @stansotn mentioned, downgrade to 16 node work for me too. Catalina (10.15.7), tools - 9.22.0

brew unlink node
brew install node@16
brew link --overwrite node@16

Can confirm, working on monterey. Thanks for the commands.

@ruohola
Copy link

ruohola commented Nov 18, 2021

I got the emulators running again by specifying host as "127.0.0.1" instead of the default "localhost". I have no idea what changed that caused it to stop working on localhost. All I did was modify firebase.json like so to add host

 "emulators": {
        "auth": {
            "port": 9099,
            "host": "127.0.0.1"
        },
        "functions": {
            "port": 5001,
            "host": "127.0.0.1"
        },
        "firestore": {
            "port": 8080,
            "host": "127.0.0.1"
        },
        "hosting": {
            "port": 5001
        },
        "ui": {
            "enabled": true
        },
        "pubsub": {
            "port": 8085,
            "host": "127.0.0.1"
        },
        "storage": {
            "port": 9199,
            "host": "127.0.0.1"
        }
    }

Worked for me, I also needed to change all my env variables to not use localhost: process.env.FIREBASE_DATABASE_EMULATOR_HOST = '127.0.0.1:9000';

@ghost
Copy link

ghost commented Nov 24, 2021

Downgrading to node 16 resolved the issue for me.
Arch Linux (for search engines)

@yuchenshi
Copy link
Member

Closing since downgrading to Node.js 16 seems to be a good workaround. Feel free to comment if you have more information or if this problem still persists when Node.js 18 becomes the new stable release.

@msrumon
Copy link

msrumon commented Jan 3, 2022

Confirmed that #2379 (comment) works. I'm on Windows 10 Pro machine with Node.js v17.2.0.

@svenjacobs
Copy link

I'm having the same timeout issue with Node 17. In case you are using Volta for managing your Node versions, you can use the volta command for running firebase with a specific Node version, for example:

volta run --node 16.14.0 firebase emulators:start

@ninest
Copy link

ninest commented Jun 4, 2022

I found this issue after Googling the error:

error - Error: Error while making request: connect ECONNREFUSED ::1:9099. Error code: ECONNREFUSED

#2379 (comment) sent me in the right direction. All I had to do was change localhost to 127.0.0.1 in the environment variables

FIREBASE_AUTH_EMULATOR_HOST = "127.0.0.1:9099"

But my firebase.json is still the same and there seem to be no issues:

{
  "emulators": {
    "auth": {
      "port": 9099
    },
    "ui": {
      "enabled": true,
      "port": 9098
    }
  }
}

(I am only using Firebase and the emulator for authentication)

@ktsin
Copy link

ktsin commented Jul 13, 2022

Just FYI same behavior on Windows machine with latest firebase tool

node -v
v18.5.0
firebase --version
11.2.2

Adding "host" : "127.0.0.1" allowed to start emulator, but UI still not working. Message below appears each time i'm trying to reach emulator's UI.

[2022-07-13T12:51:39.938Z] u [FetchError]: request to http://localhost:4400/emulators failed, reason: connect ECONNREFUSED ::1:4400
    at ClientRequest.<anonymous> (C:\Users\User\.cache\firebase\emulators\ui-v1.7.0\server.bundle.js:326:16909)
    at ClientRequest.emit (node:events:537:28)
    at Socket.socketErrorListener (node:_http_client:465:9)
    at Socket.emit (node:events:537:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  type: 'system',
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED'
}
 {"metadata":{"emulator":{"name":"ui"},"message":"u [FetchError]: request to http://localhost:4400/emulators failed, reason: connect ECONNREFUSED ::1:4400\n    at ClientRequest.<anonymous> (C:\\Users\\User\\.cache\\firebase\\emulators\\ui-v1.7.0\\server.bundle.js:326:16909)\n    at ClientRequest.emit (node:events:537:28)\n    at Socket.socketErrorListener (node:_http_client:465:9)\n    at Socket.emit (node:events:537:28)\n    at emitErrorNT (node:internal/streams/destroy:151:8)\n    at emitErrorCloseNT (node:internal/streams/destroy:116:3)\n    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {\n  type: 'system',\n  errno: 'ECONNREFUSED',\n  code: 'ECONNREFUSED'\n}\n"}}

[UPDATE]
Extra strange, but I can reach http://localhost:4400/emulators via browser and see list of configured "nodes".
image

@bkendall
Copy link
Contributor

(internal bug reference: b/172852315)

@christhompsongoogle
Copy link
Contributor

Hi everyone, there have been some changes recently to the IP resolution logic - if anyone is still hitting this issue please leave a comment.

@VikashFluxon
Copy link

VikashFluxon commented Oct 21, 2022

I faced similar error where it failed to initialise the ports and faced a timeout while checking for it to be active.
I checked the logs and it had the following message.
'auth: Port 5002 is available on 127.0.0.1 but not ::1. This may cause issues with some clients.'
It suggested me to change the port and try. I did and it worked but I am still curious as to why it did not work with 500X ports.

This started happening after the latest firebase release.
https://github.com/firebase/firebase-tools/releases/tag/v11.14.4

@christhompsongoogle
Copy link
Contributor

Hi VikashFluxon, please open a new ticket with the relevant repro case(s) and logs.

@mono-sudo2
Copy link

Hi everyone!
I ran into this issue and am unsure how to fix it.
I hope this is the right place to post this.

My Console Output:

i emulators: Starting emulators: firestore
i firestore: Importing data from ...location/firestore/backup/backup/backup_1.overall_export_metadata
⚠ firestore: Did not find a Cloud Firestore rules file specified in a firebase.json config file.
⚠ firestore: The emulator will default to allowing all reads and writes. Learn more about this option: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration.
i firestore: Firestore Emulator logging to firestore-debug.log
i emulators: Shutting down emulators.
i firestore: Stopping Firestore Emulator
i hub: Stopping emulator hub

Error: TIMEOUT: Port 8080 on 127.0.0.1 was not active within 60000ms

My firebase-export-metadata.json:
{ "version": "11.16.1", "firestore": { "version": "1.15.1", "path": "backup/backup", "metadata_file": "backup/backup/backup_1.overall_export_metadata" } }

I believe the cause to be the size of the dataset (it's about 7GB).
I was trying to find a way to increase the timeout time, but couldn't find it.
Maybe someone here could help me out?

Thanks in advance!

@christhompsongoogle
Copy link
Contributor

Is the problem reproducible with smaller sets of data? < 100MB type of size

@ciriousjoker
Copy link

ciriousjoker commented Jun 14, 2023

Can't test with <100mb, but with 750mb it's still reproducible. Also, is there a way to increase the timeout? Idc if I have to wait an hour as long as it works. I'm just using the emulator to look at backups and afaik there is no way to "shrink" them by filtering for only the collections I'm interested in.

EDIT:
So apparently, when running without export JAVA_TOOL_OPTIONS="-Xmx4g", it will throw a heap error. When setting the JAVA_TOOL_OPTIONS variable to 4g, it would throw no error and time out. When running the jar directly, it will throw a heap error.

Solution:
Increase to 8g, no more timeout. Probably doesn't scale very well, but for my usecase with 750gb it seems to work...

@IncognitoGK9
Copy link

Is there a step by step known documentation on how to configure firebase emulator to work with either the android/ios emulator or read devices, for me, NONE of the above has ever worked for me. The only thing which works is using the firebase emulators with web (Chrome or Edge) or connecting directly to Firebase live. Those works like charm. But connecting android emulator with firebase emulators or real device with firebase emulator has NEVER worked despite all those snip steps. Is there a known step by step procedure on this, this will be useful. The documentation on Firebase seems to miss a lot, and even the codelabs still do not point exactly what is to be done when, where and how. To me it seems it is all guesswork.

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

Successfully merging a pull request may close this issue.