I have created Scheduler Job that run every five minutes with a HTTP target. The HTTP target a cloud function which will sleep for 2 min and then send 200 OK response. The function doesn’t run any other logic. I verified that function executes successfully from logs as well.
Since the Scheduler job has a default attempt deadline of 3 mins, it should pass but around 1 min. It fails with URL_UNREACHABLE-UNREACHABLE_5xx. Original HTTP response code number = 502 error. If I decrease the sleep time to under 1 min, the scheduler job succeeds.
I have tried various attempt deadlines above 1 min but none of them work. Does anyone else has same problem?
Hey! We’ve seen that your question hasn’t gotten a response yet. We’ll keep checking in on this thread and encourage other members to share their thoughts.
You’re right with a 3-minute attempt deadline and a function that sleeps for 2 minutes and returns 200 OK, it should succeed. The “URL_UNREACHABLE-UNREACHABLE_5xx. Original HTTP response code number = 502 error” error suggests a networking problem or a timeout occurring before the function even has a chance to complete its sleep.
Try to Increase Cloud Function Timeout:
Go to your Cloud Function in the Google Cloud Console.
Click the “Edit” button.
In the “Runtime, build, connections and security settings” section, find the “Timeout” setting.
Increase the timeout value to at least 3 minutes (180 seconds) to accommodate your 2-minute sleep. A slightly higher value (e.g., 200 seconds) is recommended to account for network latency. The maximum timeout for HTTP functions is 540 seconds (9 minutes).
To Increase Cloud Function in Google console, here is the CLI command:
gcloud functions deploy YOUR_FUNCTION_NAME \
--runtime python39 \
--trigger-http \
--timeout=180s # Or higher, up to 540s
If you need further assistance and any questions, please reach out to our Google Cloud Support team.
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.
The cloud function has a 3 min timeout. So 2 min sleep should be just fine. The function executes without a problem. If timeout happens on the function, it’s usually visible in the Cloud Logging logs. But no such thing happens.
The problem, as I see it is, the cloud scheduler has to wait 3 mins regardless of the function behaviour. It’s can’t declare after 1 min that job has failed. This seems like a bug in cloud scheduler to me.
I think I know the issue. The problem is lies with the HTTP endpoint not the scheduler in my case. The HTTP endpoint has been hosted on Firebase Functions and It was using Firebase Rewrites. Probably the issue is in the Firebase Rewrite layer.
I discovered this accidentally trying to call another endpoint that took a long time to execute. When I tried to execute endpoint with cloud run domain, it has worked successfully.