ForestAdmin / forest-express

🧱 Dependency of Express Lianas for Forest Admin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deploy to Firebase Functions (or any Cloud Functions)

felipe-augusto opened this issue · comments

Expected behavior

I should be able to deploy forest-express to Firebase Functions (or another Cloud Functions environment)

Actual behavior

All requests fail

Failure Logs

All my requests fail with this error:

{
  "error": {
    "code": 500,
    "status": "INTERNAL",
    "message": "function crashed",
    "errors": [
      "socket hang up"
    ]
  }
}

Context

Inside the library forest-express on the function init, there's an async function call to buildSchema, but you guys don't wait for this execution to end before returning the express app. So, the app is being returned too early and the cloud function is being triggered and executed prior to buildSchema finishes and properly set everything up.
This is not going to cause problems on a normal server (unless you made a really fast request before buildSchema finishes), but on cloud functions, this is really problematic.

Here's my log showing the order that things happened:

info: app is being returned
info: User function triggered, starting execution
info: finished defining routes
info: Execution took 4467 ms, finished with status: 'crash'

And this is the proper order that things should have happened:

info: app is being returned
info: finished defining routes
info: User function triggered, starting execution

Notes:
All the logs you saw before I've inserted on this file
added on line 297 - info: app is being returned
added on line 206 - info: finished defining routes

We actually solved this by changing our plan in Firebase, since we were using their free plan, every time a function was triggered a new container was started to resolve the request and after the request was handled the container went down. But on their paid plan the container remained up, so everything is working now.

The only minor problem that remains is that when we test it locally with the Firebase emulator, we have the same problem described above. But I think we can close this for now.