---
title: A fuzzer said "deadlock". The real cause was the server's region
date: 2026-11-20
tags: cloud-run, firestore, latency, mcp, gcp-regions
type: success
status: n/a
reproducible: true
visibility: public
stack: Node.js / TypeScript MCP server on Google Cloud Run, Firestore (firebase-admin)
agent: Claude Code
model: claude-opus-5-5
---

# A fuzzer said "deadlock". The real cause was the server's region

Every app has parts that live somewhere: the server in one data centre, the database in another. You pick each place once, months apart, and then forget. Nothing warns you when the two are on different continents. Everything works, just slowly, and the slowness looks like your code.

My AimYear MCP server answered `get_now` in about 3 seconds and `get_planning_context` in 7 to 9, in production. I only looked because a fuzzer, [mcp-crashtest](https://github.com/SnowyLumiere/mcp-crashtest), reported three "stdio deadlocks". They weren't deadlocks: the server answered, just late. My agent read the code and blamed it: `get_now` makes about 16 Firestore reads one after another. That was true, but it wasn't the whole answer.

Then it compared two settings. Firestore was in `eur3` (Europe). The Cloud Run service was in `us-central1`, the region in every deploy command in my README. Every one of those 16 reads crossed the Atlantic and back, about 150 ms each.

We deployed the same image to `europe-west1` and kept the US copy running, so both could be measured at the same moment: 8 read-only tools, 10 calls each, same account, same database. Server-side median times from the Cloud Run logs:

| tool | us-central1 | europe-west1 |
|---|---|---|
| get_planning_context | 7503 ms | 584 ms |
| summarize_week | 4200 ms | 373 ms |
| get_now | 2850 ms | 263 ms |
| list_sessions | 256 ms | 30 ms |

No code changed. Two things we learned on the way:

- Not every service should move. My app's other backend never reads Firestore; it only calls AI APIs that are in the US. Moving it to Europe would make it slower, so it stayed.
- A Cloud Run domain mapping can't serve two regions, so moving the custom domain means deleting the old mapping and creating a new one. The new certificate took 11 minutes; `/health` answered the whole time. Calls through the custom domain still cost me about 0.9 s more than the plain run.app address (the TCP connect alone took 0.31 s vs 0.02 s from my location), which is the domain-mapping path, not the region.

The undocumented part: the cost of the wrong region is per read, so it multiplies with every sequential query. One read per request hides it (list_sessions lost 0.2 s); a tool that makes 16 reads loses 3 seconds.

## Check if this applies to you

Applies if: a Google Cloud project with a Cloud Run service (or Cloud Functions / App Engine) that reads Firestore. Same idea for any server and database, if you can see where each one runs.

Read-only steps:
1. `gcloud firestore databases list --project <PROJECT> --format="table(name,locationId)"`
2. `gcloud run services list --project <PROJECT> --format="table(metadata.name,metadata.labels.'cloud.googleapis.com/location')"`
3. For each service that uses Firestore, compare its region with the database location. `eur3` is served from europe-west1 and europe-west4; `nam5` from us-central1 and nearby US regions; a single-region database like `europe-west3` matches only that region.

Has the problem: a service that reads Firestore runs on another continent from the database (for example `us-central1` with `eur3`).
Doesn't have it: every service that reads Firestore runs in or next to the database's location.

## Reproduce this

Prerequisites: a Cloud Run service that reads Firestore and runs on another continent from it (the check above says "has the problem"); `gcloud` signed in with rights to deploy Cloud Run, edit Cloud Scheduler jobs and domain mappings.

Your agent will need from you: the project id, the service name, the target region (one listed next to your database location), and a yes before touching the custom domain.

Steps:
1. Measure before. Time a few read-heavy calls against the current service, and note the server-side times from the logs if your service logs them (mine logs `ms` per tool call).
2. Find everything that points at the old service's address, not the custom domain: Cloud Scheduler jobs (`gcloud scheduler jobs list --location <region>`), Pub/Sub push subscriptions, clients and scripts with the `run.app` URL in their code. Mine had a minute tick in Cloud Scheduler and a Mac menu-bar app.
3. Copy the service with the same image, so the code is identical: `gcloud run services describe <SERVICE> --region <OLD> --format export > svc.yaml`, remove the `run.googleapis.com/build-*`, `urls`, `ingress-status` and `maxScale` metadata annotations and the `client.knative.dev/nonce` label, set the location label to the new region, then `gcloud run services replace svc.yaml --region <NEW>`. Copy the IAM policy too (for a public service: `allUsers` with `roles/run.invoker`).
4. Measure the new copy against its own `run.app` URL with the same calls as step 1. Keep the old copy running while you compare.
5. Move what pointed at the old address: `gcloud scheduler jobs update http <JOB> --location <JOB_LOCATION> --uri <new URL>`. A job that does work for every user (reminders, sends) must call only one copy, so switch it, don't add a second one.
6. Move the custom domain: `gcloud beta run domain-mappings delete --domain <DOMAIN> --region <OLD>`, then `gcloud beta run domain-mappings create --service <SERVICE> --domain <DOMAIN> --region <NEW>`. The DNS record (CNAME to `ghs.googlehosted.com`) stays the same; wait until the mapping's `CertificateProvisioned` condition is True.
7. Change the region in every deploy command in your docs and scripts, or the next release goes to the old copy and the domain keeps serving old code.
8. Delete the old copy only when nothing calls it any more (check its request logs).

Verify: the same calls from step 1, against the new region, are faster; the server-side times in the logs for the read-heavy tools drop (mine: get_now 2850 → 263 ms); the custom domain's requests show up in the new region's logs and none in the old one's, except callers you chose to leave; the scheduled job's calls appear in the new region's logs.
