firebasegoogle-cloud-functionscorsfirebase-app-check

Firebase function CORS preflight request very slow after inactivity


I have an issue where the CORS preflight (OPTIONS) request for an intermittently-used Firebase function takes some 8 seconds when the function hasn't been used recently. I'm using Firebase's App Check, so I don't have direct control over CORS config. The actual function execution time is normal, and subsequent preflight requests are processed quickly until the function becomes inactive again.

From a HAR file:

Request method: OPTIONS
Wait time: 7299 ms

I wouldn't expect the infrastructure handling CORS preflight requests to be subject to cold starts in the same way as my actual function execution. Is an 8-second delay for a preflight request a normal occurrence due to cold starts, or could there be another issue? Thanks for any thoughts!


Solution

  • It sounds like you're seeing a cold start, which happens when the Cloud Functions environment has to start a new instance to run your code.

    If you want to reduce the chances of that, you can keep a minimum number of instances warm (at a cost).

    See the documentation on Configure minimum instances and Reduce cold starts by setting a minimum number of instances .