invertase / stripe-firebase-extensions

Repository of Firebase Extensions built by Stripe.
https://firebase.google.com/products/extensions
Apache License 2.0
437 stars 172 forks source link

Request to Firebase Extensions url for Firestore Stripe Payments often fails #405

Open alexdao3 opened 2 years ago

alexdao3 commented 2 years ago

Bug report

Describe the bug

In one of our CI (Github Actions) workflows, we start up the emulator w/ extensions & run tests against it. The extensions are defined in firebase.json config, one of which is

"firestore-stripe-subscriptions": "stripe/firestore-stripe-payments@0.2.4".

During startup, the emulator appears to make a request to https://firebaseextensions.googleapis.com/v1beta/publishers/stripe/extensions/firestore-stripe-payments. Oftentimes this request fails and we get the following error:

Error: Failed to make request to https://firebaseextensions.googleapis.com/v1beta/publishers/stripe/extensions/firestore-stripe-payments

Occasionally we don't see this error, and the emulator successfully starts up (presumably this means that the request above succeeds). Even when re-running the same CI workflow (without any changes to anything), the request may fail on the first run but succeed on the second run (or vice versa)

So far we've only observed this inconsistent behavior in CI and have never encountered this error on local dev w/ emulators.

For the Github action workflow, I'm providing the following env variables:

FIREBASE_TOKEN (generated via "npx firebase login:ci")
PROJECT_ID

and invoking

npx firebase use --add "$PROJECT_ID"
npx firebase emulators:exec 'npm run test'

To Reproduce

I don't currently have a minimal reproducible example due to this being in our private GH actions workflow, but let me know if this is necessary and I can try to create a minimal public version.

Expected behavior

I expect the emulators to be able to start up or get some feedback as to why the request was unsuccessful. I also expect the behavior to be consistent between consecutive CI runs (when there are no code changes)

Screenshots

When this fails:

image

System information

dackers86 commented 2 years ago

HI @alexdao3

It seems like some processes are taking place before the emulator (or some other process) is starting up?

Do you have any additional debugging, or can you provide any details? It is difficult to see which of the api calls could be causing the issue.

alexdao3 commented 2 years ago

@dackers86 Thanks for the reply!

It seems like some processes are taking place before the emulator (or some other process) is starting up?

Could you point to the logs that indicate there are other processes taking place before the emulator starts up? Based on my understanding, running npx firebase emulators:exec 'npm run test' starts up the emulator before running npm run test, so the only process that should be running when the API request fails is npx firebase emulators.

Do you have any additional debugging, or can you provide any details? It is difficult to see which of the api calls could be causing the issue.

I did a slightly more targeted query based on your example and I wonder if that helps narrow which of the API calls might be causing this.

I'm also running the bigquery extension (which you can see from the logs), and that one doesn't any issues at all. It's only the Stripe extension that seems to be problematic (maybe 75% of the time it fails; 25% of the time I don't see a failure), and it's only happening in CI

Let me know what additional details / debugging might be helpful, and I can try to get that for you?

alexdao3 commented 2 years ago

Your question about additional debugging spurred me to try running npx firebase emulators... --debug. I had forgotten there was a --debug option. Hopefully it'll yield interesting information - I'll share back if so!

alexdao3 commented 2 years ago

@dackers86 That gave us some more info to work with! I've attached inline a subset of the logs dealing with the exact error + attached a .txt file with more detailed logging

firestore-stripe-extension-debug-log.txt

Seems like we make the API call for the firestore-stripe-payments url, but it times out

2022-07-15T19:08:35.3725729Z i  extensions: Downloaded to /home/runner/.cache/firebase/extensions/stripe/firestore-stripe-payments@0.2.4... {"metadata":{"emulator":{"name":"extensions"},"extension":{"ref":"stripe/firestore-stripe-payments@0.2.4"},"message":"Downloaded to /home/runner/.cache/firebase/extensions/stripe/firestore-stripe-payments@0.2.4..."}}
2022-07-15T19:08:36.3738667Z [2022-07-15T19:08:36.373Z] [Extensions] Running "npm install" for /home/runner/.cache/firebase/extensions/stripe/firestore-stripe-payments@0.2.4
2022-07-15T19:08:48.5960186Z [2022-07-15T19:08:48.592Z] [Extensions] Finished "npm install" for /home/runner/.cache/firebase/extensions/stripe/firestore-stripe-payments@0.2.4
2022-07-15T19:08:48.5961924Z [2022-07-15T19:08:48.592Z] [Extensions] Running "npm run gcp-build" for /home/runner/.cache/firebase/extensions/stripe/firestore-stripe-payments@0.2.4
2022-07-15T19:08:48.9647221Z [2022-07-15T19:08:48.964Z] [Extensions] Finished "npm run gcp-build" for /home/runner/.cache/firebase/extensions/stripe/firestore-stripe-payments@0.2.4
2022-07-15T19:08:48.9661171Z ⚠  Function 'createPortalLink is missing a trigger in extension.yaml. Please add one, as triggers defined in code are ignored. {"metadata":{"emulator":{"name":"functions"},"message":"Function 'createPortalLink is missing a trigger in extension.yaml. Please add one, as triggers defined in code are ignored."}}
2022-07-15T19:08:48.9663518Z ⚠  Function 'handleWebhookEvents is missing a trigger in extension.yaml. Please add one, as triggers defined in code are ignored. {"metadata":{"emulator":{"name":"functions"},"message":"Function 'handleWebhookEvents is missing a trigger in extension.yaml. Please add one, as triggers defined in code are ignored."}}
2022-07-15T19:08:48.9685502Z [2022-07-15T19:08:48.968Z] >>> [apiv2][query] GET https://firebaseextensions.googleapis.com/v1beta/publishers/stripe/extensions/firestore-stripe-payments [none]
2022-07-15T19:09:30.8343102Z [2022-07-15T19:09:30.834Z] >>> [apiv2][query] GET https://firebaseextensions.googleapis.com/v1beta/publishers/firebase/extensions/firestore-bigquery-export [none]
2022-07-15T19:09:30.8425692Z i  emulators: Shutting down emulators. {"metadata":{"emulator":{"name":"hub"},"message":"Shutting down emulators."}}
2022-07-15T19:09:30.8432324Z i  hub: Stopping emulator hub {"metadata":{"emulator":{"name":"hub"},"message":"Stopping emulator hub"}}
2022-07-15T19:09:30.8463582Z [2022-07-15T19:09:30.845Z] FetchError: request to https://firebaseextensions.googleapis.com/v1beta/publishers/stripe/extensions/firestore-stripe-payments failed, reason: Client network socket disconnected before secure TLS connection was established
2022-07-15T19:09:30.8465672Z     at ClientRequest.<anonymous> (/home/runner/work/gatheround/gatheround/node_modules/firebase-tools/node_modules/node-fetch/lib/index.js:1491:11)
2022-07-15T19:09:30.8468519Z     at ClientRequest.emit (node:events:390:28)
2022-07-15T19:09:30.8469072Z     at ClientRequest.emit (node:domain:475:12)
2022-07-15T19:09:30.8471852Z     at TLSSocket.socketErrorListener (node:_http_client:447:9)
2022-07-15T19:09:30.8472438Z     at TLSSocket.emit (node:events:390:28)
2022-07-15T19:09:30.8472922Z     at TLSSocket.emit (node:domain:475:12)
2022-07-15T19:09:30.8473442Z     at emitErrorNT (node:internal/streams/destroy:157:8)
2022-07-15T19:09:30.8474021Z     at emitErrorCloseNT (node:internal/streams/destroy:122:3)
2022-07-15T19:09:30.8474655Z     at processTicksAndRejections (node:internal/process/task_queues:83:21)
2022-07-15T19:09:30.8475086Z 
2022-07-15T19:09:30.8475989Z Error: Failed to make request to https://firebaseextensions.googleapis.com/v1beta/publishers/stripe/extensions/firestore-stripe-payments
2022-07-15T19:09:31.0626147Z [2022-07-15T19:09:31.061Z] <<< [apiv2][status] GET https://firebaseextensions.googleapis.com/v1beta/publishers/firebase/extensions/firestore-bigquery-export 200
2022-07-15T19:09:31.0633416Z [2022-07-15T19:09:31.062Z] <<< [apiv2][body] GET https://firebaseextensions.googleapis.com/v1beta/publishers/firebase/extensions/firestore-bigquery-export {"name":"publishers/firebase/extensions/firestore-bigquery-export","ref":"firebase/firestore-bigquery-export","latestVersion":"0.1.24","latestVersionCreateTime":"2022-06-22T20:57:35.234393Z","state":"PUBLISHED","createTime":"2021-03-18T22:00:55.231242Z","visibility":"PUBLIC","registryLaunchStage":"BETA","iconUri":"https://www.gstatic.com/mobilesdk/200707_mobilesdk/export_bigquery_120@2x.png","publisher":{"iconUri":"https://www.gstatic.com/mobilesdk/160503_mobilesdk/logo/2x/firebase_128dp.png"}}
2022-07-15T19:09:31.1235509Z ##[error]Process completed with exit code 1.
dackers86 commented 2 years ago

Could you confirm what version of the Firebase cli and node are you using?

Firebase --version

Node -v

alexdao3 commented 2 years ago

Node 16.13.1 Firebase tools 11.2.2

alexdao3 commented 2 years ago

@dackers86 Do you have any insight into this issue?

alexdao3 commented 2 years ago

@dackers86 Hi Darren, just wanted to follow up to see if you had any ideas on this failing request

nickpell commented 2 years ago

@dackers86 @jsteele-stripe Do you have any insight into the issue my colleague described above?

jelling commented 1 year ago

Could the issue here be literally what the error message says?

Error:

2022-07-15T19:08:48.9661171Z ⚠  Function 'createPortalLink is missing a trigger in extension.yaml. Please add one, as triggers defined in code are ignored. {"metadata":{"emulator":{"name":"functions"},"message":"Function 'createPortalLink is missing a trigger in extension.yaml. Please add one, as triggers defined in code are ignored."}}
2022-07-15T19:08:48.9663518Z ⚠  Function 'handleWebhookEvents is missing a trigger in extension.yaml. Please add one, as triggers defined in code are ignored. {"metadata":{"emulator":{"name":"functions"},"message":"Function 'handleWebhookEvents is missing a trigger in extension.yaml. Please add one, as triggers defined in code are ignored."}}

And those functions don't have a trigger:

  - name: createPortalLink
    type: firebaseextensions.v1beta.function
    description: >-
      Creates links to the customer portal for the user to manage their payment & subscription details.
    properties:
      location: ${LOCATION}
      runtime: nodejs14
      httpsTrigger: {}

  - name: handleWebhookEvents
    type: firebaseextensions.v1beta.function
    description: >-
      Handles Stripe webhook events to keep subscription statuses in sync and update custom claims.
    properties:
      location: ${LOCATION}
      runtime: nodejs14
      httpsTrigger: {}
alexdao3 commented 1 year ago

@jelling Even when those warning logs are present, I'm often able to run the emulators with the Stripe extension. I don't think the warnings are necessarily related to the failing GET request to https://firebaseextensions.googleapis.com/v1beta/publishers/stripe/extensions/firestore-stripe-payments