High severity intermediate · Fix: 5-15 min

TimeoutError

modal.client.exceptions.TimeoutError

What this error means
Modal function deployment fails because the deployment process exceeds the allowed time limit and times out.

Stack trace

traceback
modal.client.exceptions.TimeoutError: Function deployment timed out after 300 seconds
  File "/usr/local/lib/python3.9/site-packages/modal/client.py", line 512, in deploy
    raise TimeoutError("Function deployment timed out after 300 seconds")
QUICK FIX
Reduce function startup time or increase the deployment timeout setting to prevent timeout errors.

Why it happens

Modal deploy timeout occurs when the function build or container startup takes longer than the configured timeout period, often due to large dependencies, slow network, or heavy initialization code. The deployment process waits for the function to become ready but aborts after the timeout.

Detection

Monitor deployment logs and catch modal.client.exceptions.TimeoutError exceptions during deploy calls to detect when deployment exceeds the timeout threshold.

Causes & fixes

1

Large or numerous dependencies cause slow container build and startup.

✓ Fix

Optimize your Dockerfile or requirements to reduce dependency size and build time, or pre-build and cache images if supported.

2

Heavy initialization code in the function delays readiness beyond timeout.

✓ Fix

Refactor initialization to be lazy or faster, or move heavy setup outside the function deploy path.

3

Network slowness or connectivity issues delay deployment steps.

✓ Fix

Check network stability and retry deployment in a better network environment.

4

Default deployment timeout is too short for your function's build and startup time.

✓ Fix

Increase the deployment timeout setting in your Modal client configuration if supported.

Code: broken vs fixed

Broken - triggers the error
python
import modal

stub = modal.Stub()

@stub.function
async def my_function():
    # some code

stub.deploy()  # This line raises TimeoutError after waiting too long
Fixed - works correctly
python
import os
import modal

os.environ["MODAL_API_KEY"] = os.getenv("MODAL_API_KEY")  # Ensure API key is set

stub = modal.Stub()

@stub.function
async def my_function():
    # some code

# Increase timeout or optimize function to avoid timeout
stub.deploy(timeout=600)  # Increased timeout to 600 seconds
Increased the deploy timeout parameter to allow more time for function build and startup, preventing premature timeout errors.

Workaround

Wrap the deploy call in try/except modal.client.exceptions.TimeoutError, then retry deployment or alert the user to try again later.

Prevention

Design functions with minimal startup overhead and optimize dependencies; configure deployment timeout settings appropriately to avoid hitting timeouts.

Python 3.9+ · modal >=0.7.0 · tested on 0.9.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.