Slackbot
04/23/2026, 3:09 PMMarvin
04/23/2026, 3:09 PMMarvin
04/23/2026, 3:09 PMMarvin
04/23/2026, 3:10 PMMarvin
04/23/2026, 3:13 PMaddress already in use on 127.0.0.1:8781
- AssertionError: Reactive triggers not started
- failures inside Flow.ato_deployment() / RunnerDeployment.afrom_storage()
- then Failed to clone repository ...
That combination strongly suggests that during deployment Prefect is spinning up local temporary server/process resources, and when you deploy many flows in the same job/container those resources are colliding or not cleaning up correctly. The repo clone failures are likely a downstream symptom once the local deployment machinery gets into a bad state.
A few important notes:
1. The fixed number of 8 is a clue
If it always tops out around 8, that usually means some bounded local resource is being exhausted or contended:
- local subprocesses
- temp server instances / ports
- clone destinations / locks
- event/reactive trigger startup/shutdown state
2. The 8781 bind error is likely the smoking gun
Something in the deployment path is trying to start a local server on a loopback port, and subsequent deployments are colliding on it.
3. Parallel vs sequential not helping
That implies the issue is not just your asyncio.gather(...), but that repeated deployments in the same process/container are reusing shared local state.
I also checked the current CLI shape, and prefect deploy is the correct 3.x command:
- Prefect docs
- CLI confirms prefect deploy [ENTRYPOINT]
What I’d recommend trying first:
Best workaround: avoid per-flow source cloning / local storage resolution repeatedly in the same process
Instead of calling flow_obj.to_deployment() / ato_deployment() many times against the same Git source in one job, prefer one of these approaches:
Option A: use prefect deploy from a project with prefect.yaml
If your flows are already in the container filesystem, deploy from local code instead of making each deployment re-pull the repo.
Option B: use flow.from_source(...).deploy(...) once per flow, but from a script that is not doing massive concurrent deployment
And if possible, split the deployment batch into smaller separate job invocations.
Option C: if you're on Prefect Cloud, make sure PREFECT_API_URL points directly to Cloud
That avoids any fallback behavior that may be starting local ephemeral server components.
Things to verify in your Cloud Run Job environment:
bash
echo $PREFECT_API_URL
echo $PREFECT_API_KEY
prefect config view
You want PREFECT_API_URL to be your Prefect Cloud workspace API, not a local URL.
A practical mitigation plan:
1. Upgrade Prefect to the latest 3.x available
There have been recent fixes around deployment/storage concurrency behavior.
2. Stop deploying all flows in one Python process
Even if you do it sequentially, the shared process may retain bad state.
Try:
- one prefect deploy per process
- or batches of, say, 5 flows per job
3. Avoid ato_deployment() against the same git repo repeatedly if the code is already present locally
Your traceback shows:
- afrom_storage
- storage.pull_code()
- _clone_repo()
That means each deployment is going through storage cloning logic. If the code is already in the job image, that's unnecessary and more fragile.
4. Try deploying from local source instead of git source inside the deployment step
For example, use a normal project deployment layout and run:
bash
prefect deploy --all
from the checked-out project directory.
5. If you must keep the Python deploy script, avoid asyncio.gather and isolate each deployment in a subprocess
Not ideal, but it prevents shared in-memory state collisions.
Example pattern:
```python
import subprocess
import sys
flows = [
"./flows/a.py:flow_a",
"./flows/b.py:flow_b",
]
for entrypoint in flows:
result = subprocess.run(
["prefect", "deploy", entrypoint],Marvin
04/23/2026, 3:13 PMato_deployment() calls in one interpreter.
If you want, I can help you refactor your current script away from this pattern.
Two likely root causes in your specific setup:
- shared local server state / port collision causing the 8781 bind failure
- repeated git clone/storage resolution during afrom_storage() causing the later repo clone errors
If you can share:
- your Prefect version
- whether you're using Prefect Cloud or Server
- how each flow is being constructed before to_deployment()
- whether the repo is already present in the Cloud Run image
I can suggest the safest exact deployment pattern for your setup.
Relevant links:
- Deploy via Python
- Deploy with prefect.yaml
- Flow API docs
- Deployments overview
If you want, paste the part of your script where you build flow_obj and call to_deployment(), and I’ll show you the least invasive fix.