CodexBloom - Programming Q&A Platform

GCP Cloud Run service returning '503 Service Unavailable' when deployed with custom runtime

πŸ‘€ Views: 240 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-10
google-cloud-platform cloud-run node.js JavaScript

I tried several approaches but none seem to work. I'm running into an scenario with my GCP Cloud Run service deployed using a custom runtime based on Node.js 14. When I deploy the service, it works fine initially, but after a few minutes, it starts returning a '503 Service Unavailable' behavior when I try to access the endpoint. I have set the maximum instances to 5, and I suspect it might be related to the way I'm handling requests in my application. Here's a snippet of how I'm setting up my Express app: ```javascript const express = require('express'); const app = express(); app.get('/', (req, res) => { // Simulating some asynchronous operation setTimeout(() => { res.send('Hello World!'); }, 60000); // 1 minute delay }); const PORT = process.env.PORT || 8080; app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); }); ``` I noticed that if I keep the delay under 30 seconds, the service responds as expected. However, with the longer delay, I see the following logs: ``` behavior: Response to client was not sent within the time limit ``` I’ve tried increasing the request timeout in my Cloud Run configuration to 10 minutes, but it doesn’t seem to resolve the scenario. Also, I am using the latest Google Cloud SDK for deployment. My Dockerfile looks like this: ```dockerfile FROM node:14 WORKDIR /usr/src/app COPY package*.json ./ RUN npm install COPY . . CMD [ "node", "app.js" ] ``` Has anyone experienced this before? What could be causing the '503 Service Unavailable' response after a period? Any recommendations on best practices for handling long-running requests in Cloud Run? Thanks in advance!