Prompt
Why is my function timing out on a serverless platform?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
A function usually times out on a serverless platform because it’s taking longer than the platform’s maximum execution limit for a single invocation. Common causes:
- Long-running work: CPU-heavy loops, large data processing, image/video transcoding, etc.
- Slow I/O: Calls to databases, APIs, S3/storage, or third-party services that take too long.
- Too much data: Processing large payloads or reading/writing too many records at once.
- Cold starts + work combined: Startup latency plus actual processing pushes it over the limit.
- Blocking code: Synchronous operations or waiting on resources can stall progress.
- Infinite loops / retries: Logic bugs, repeated retries, or waiting forever on a condition.
- Resource constraints: Too little memory/CPU can make the function slow enough to time out.
- Dependency issues: DNS delays, network timeouts, or downstream service slowness.
What to check:
- Platform timeout setting — confirm the max allowed duration.
- Logs/trace — identify which step consumes the time.
- External calls — add shorter client-side timeouts and retries with backoff.
- Break up the work — use queues, batch processing, step functions/workflows, or async jobs.
- Optimize cold starts — reduce package size, lazy-load dependencies, or keep functions warm if supported.
- Increase memory — on many platforms, more memory also means more CPU.
- Measure locally — benchmark the slow path with realistic input.
If you want, paste the function code and the platform you’re using (AWS Lambda, Cloud Functions, Azure Functions, etc.), and I can help pinpoint the likely bottleneck.