firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.01k stars 925 forks source link

Upgraded firebase deps and it broke pubsub function emulation #2710

Open stephenhandley opened 3 years ago

stephenhandley commented 3 years ago

I upgraded Firebase deps and I am now seeing the following error when locally emulating PubSub functions. These were all previously working. HTTP functions are still running fine.

Function ignored because the pubsub emulator does not exist or is not running

I've confirmed via the logs and curl that the emulator is in fact running

$ curl localhost:8085
Ok

Logs

$ /* DELETED */ firebase emulators:start --only functions,pubsub
i  emulators: Starting emulators: functions, pubsub
⚠  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, firestore, database, hosting
✔  functions: Using node@12 from host.
⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to /* DELETED */ Non-emulated services will access production using these credentials. Be careful!
i  pubsub: Pub/Sub Emulator logging to pubsub-debug.log
i  ui: Emulator UI logging to ui-debug.log
i  functions: Watching /* DELETED */ for Cloud Functions...
⚠  Non-default "firebase-admin" instance created!
   - This instance will *not* be mocked and will access production resources.
⚠  Non-default "firebase-admin" instance created!
   - This instance will *not* be mocked and will access production resources.
✔  functions[/* DELETED */]: http function initialized (http://localhost:5001//* DELETED */).
✔  functions[/* DELETED */]: http function initialized (http://localhost:5001//* DELETED */).
✔  functions[/* DELETED */]: http function initialized (http://localhost:5001//* DELETED */).
i  functions[/* DELETED */]: function ignored because the pubsub emulator does not exist or is not running.
i  functions[/* DELETED */]: function ignored because the pubsub emulator does not exist or is not running.
i  functions[/* DELETED */]: function ignored because the pubsub emulator does not exist or is not running.
i  functions[/* DELETED */]: function ignored because the pubsub emulator does not exist or is not running.

┌───────────────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! View status and logs at http://localhost:4000 │
└───────────────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator  │ Host:Port      │ View in Emulator UI             │
├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ localhost:5001 │ http://localhost:4000/functions │
├───────────┼────────────────┼─────────────────────────────────┤
│ Pub/Sub   │ localhost:8085 │ n/a                             │
└───────────┴────────────────┴─────────────────────────────────┘
  Other reserved ports: 4400, 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.

[REQUIRED] Environment info

firebase-tools: 8.12.1 (upgraded from 8.2.0)

Platform: macOS 10.14.6

[REQUIRED] Test case

Described above.

[REQUIRED] Steps to reproduce

Pub sub function w/ emulator

[REQUIRED] Expected behavior

That the emulator doesn't break on upgrades

[REQUIRED] Actual behavior

Logs above

samtstern commented 3 years ago

@stephenhandley hmmm I was not able to reproduce this. I made a brand new project with these functions:

const functions = require('firebase-functions');

exports.helloWorld = functions.https.onRequest((request, response) => {
  console.log("Hello world");
  response.send("Hello from Firebase!");
});

exports.helloPubsub = functions.pubsub.topic("foo").onPublish(async (msg, ctx) => {
  console.log("Hello pubsub");
});

And here's what I got:

$ firebase emulators:start
i  emulators: Starting emulators: functions, pubsub
⚠  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, firestore, database, hosting
✔  functions: Using node@10 from host.
i  pubsub: Pub/Sub Emulator logging to pubsub-debug.log
i  functions: Watching "/private/var/folders/xl/6lkrzp7j07581mw8_4dlt3b000643s/T/tmp.T1AbEpU2/functions" for Cloud Functions...
✔  functions[helloWorld]: http function initialized (http://localhost:5001/fir-dumpster/us-central1/helloWorld).
✔  functions[helloPubsub]: pubsub function initialized.

┌──────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your apps. │
└──────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┐
│ Emulator  │ Host:Port      │
├───────────┼────────────────┤
│ Functions │ localhost:5001 │
├───────────┼────────────────┤
│ Pub/Sub   │ localhost:8085 │
└───────────┴────────────────┘
  Other reserved ports: 4400

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.

Can you help us find a simple way to reproduce this issue?

stephenhandley commented 3 years ago

@samtstern Thanks for the info. My project is closed source so I'll need to think how to best recreate the issue. One thing I figured I'd mention is that I am running my project within yarn workspaces / lerna and that I have pinned the firebase-tools dep in devDependencies in the top level package.json rather than installing it globally, not sure if that could be an issue.

In the meantime, I tried digging into the logging/source and it looks like this error is getting swallowed here: https://github.com/firebase/firebase-tools/blob/master/src/emulator/functionsEmulator.ts#L608

hihihhi got that pubsub error FirebaseError: Could not create topic /* DELETED */
    at PubsubEmulator.<anonymous> (/DERP/node_modules/firebase-tools/lib/emulator/pubsubEmulator.js:78:27)
    at Generator.throw (<anonymous>)
    at rejected (/DERP/node_modules/firebase-tools/lib/emulator/pubsubEmulator.js:6:65)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  children: [],
  context: undefined,
  exit: 1,
  original: TypeError: Channel credentials must be a ChannelCredentials object
      at new ChannelImplementation (/DERP/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/channel.js:65:19)
      at new Client (/DERP/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/client.js:57:36)
      at new ServiceClientImpl (/DERP/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/make-client.js:49:5)
      at GrpcClient.createStub (/DERP/node_modules/google-gax/build/src/grpc.js:220:22)
      at processTicksAndRejections (internal/process/task_queues.js:97:5),
  status: 500
}

I saw this related issue and I guess I'll go through and make sure I bump the versions of everything google-related. I had bumped all the firebase stuff but just noticed @google-cloud/pubsub was not the latest version.

stephenhandley commented 3 years ago

I ran gcloud components update to update to 314.0.0 re-bootstrapped node modules after bumping version didn't fix the issue, still seeing Channel credentials must be a ChannelCredentials object.

These appear to be all the relevant deps and they're at the latest versions

"@google-cloud/pubsub": "2.5.0",
"apollo-server-cloud-functions": "2.18.2",
"firebase-admin": "9.2.0",
"firebase-functions": "3.11.0",
"googleapis": "61.0.0",
stephenhandley commented 3 years ago

Ok, found this and installing google-gax fixed the issue. Might be good idea to have addFirestoreTrigger return a failure reason / throw instead of just a boolean and then have the CLI log a more informative message about this ChannelCredentials issue, perhaps suggest installing google-gax or some other appropriate fix if there is one.

samtstern commented 3 years ago

@stephenhandley thanks for digging and finding the error! I agree, we can improve logging here.