I have an ExpressJS API that I am trying to deploy on a Google App Engine. I deployed it with gcloud app deploy --version=[NEW_VERSION_NUMBER]
.
It includes a basic root endpoint that returns a 200 status code:
app.get('/', (req, res) => {
res.status(200).send('OK')
})
It also includes a GET /health-check
endpoint with the same functionality.
I have this code at the end to verify the API is listening on a port:
const PORT = process.env.PORT | 3001
app.listen(PORT, () => {
console.log(`STARTUP: Process listening on port ${PORT}`)
})
When I run gcloud app logs tail -s default
I can see that the app is starting for the new version I deployed:
2024-09-02 05:29:52 default[NEW_VERSION_NUMBER] STARTUP: Process listening on port 8121
However, when I try to send a request to any of the endpoints using this URL: https://MY_PROJECT_ID.REGION_ID.r.appspot.com
It runs for 4 minutes and then returns a 503 error. There are no error messages present in the app logs, but Log Explorer in GCP indicates that this error is happening due to a failed readiness check.
All of the code is running fine locally, and I have other logs in my app that indicate the App Engine is connecting to my database successfully.
How can I fix this?
1
To get a complete visibility of the logs, could you please run the following command with the flag
gcloud app deploy –verbosity=debug
You may observe 503 warning messages due to your app taking too long to startup and failing the readiness checks or the deployment fails because the container failed to pass the readiness checks. Another possibility is resources on the instances are maxing out. It’s difficult to point out the exact issue without checking the logs.
Some of the possibilities to fix the issue:
-
It is suggested to increase the readiness check value
app_start_timeout_sec
to the maximum value which is 1800, because it gives more time to the app to become healthy. -
If the readiness check fails due to the container not reporting
healthy, then Cloud Logging should show a 503 response. A health
check can also fail if there is no free disk space. For this try
manually increasing the resources like CPU in yourapp.yaml
file.
You can check more about this
here. -
Also remember that HTTP requests from health checks are not
forwarded to your application container by default. If you want to
extend health checks to your application, then specify a path for
liveness checks
orreadiness checks
. A customized health check
to your application is considered successful if it returns a 200 OK
response code.
Also have a look at this Link1 and Link2.
As we are not aware of your configuration part like app.yaml
file and none of the above suggestions helps you in resolving the issue, better to contact Google Support for more dedicated help on the issue.