GCP Vertex AI API requests missing timeout parameter - sync process can hang indefinitely
Expected behavior
All outbound HTTP requests in Cartography intel modules should include a timeout parameter to prevent the sync process from hanging indefinitely when an external API becomes unresponsive. This is consistent with other modules in the codebase (e.g., bigfix/computers.py, github/util.py, semgrep/deployment.py, salesforce/util.py) that all define and use a _TIMEOUT constant.
The GCP Vertex AI paginated resource fetcher (list_all_resources_paginated) should include a timeout on both the session.get() and requests.get() calls to ensure bounded execution time per API call.
Actual behavior
The function list_all_resources_paginated() in cartography/intel/gcp/vertex/utils.py (lines 259–262) makes HTTP requests without any timeout:
while True:
params: dict[str, str] = {}
if page_token:
params["pageToken"] = page_token
if session is not None:
response = session.get(url, headers=request_headers, params=params) # ← No timeout
else:
response = requests.get(url, headers=request_headers, params=params) # ← No timeout
If the GCP Vertex AI API becomes unresponsive (network partition, API outage, DNS failure after initial connection), the HTTP request blocks indefinitely. Because this code runs inside a while True pagination loop, there is no recovery path — the process hangs permanently.
This causes:
- Full pipeline stall: Cartography runs sync modules sequentially. A hung Vertex AI sync blocks all subsequent modules (AWS, Azure, GitHub, etc.) from executing.
- Silent failure: The process appears alive (not crashed) but makes no progress. Health checks that only monitor process liveness won't detect this condition.
- Resource leak: The hung connection holds a TCP socket and Python thread indefinitely, potentially exhausting connection pools in long-running deployments.
Additionally, import requests is placed inside the function body (line 248) rather than at the module level, which is a minor code quality issue (PEP 8 violation).
To Reproduce
- Configure Cartography with GCP credentials and enable the Vertex AI sync module.
- Start a Cartography sync.
- Simulate an unresponsive Vertex AI endpoint using one of the following methods:
- Block outbound traffic to
us-central1-aiplatform.googleapis.comafter the initial connection using a firewall rule. - Use a network proxy to introduce indefinite latency on the Vertex AI API responses.
- Set up a mock server that accepts the TCP connection but never sends a response.
- Block outbound traffic to
- Observe that the Cartography sync process hangs at the Vertex AI resource fetch step and never recovers or times out.
Logs
No error logs are produced — the process simply hangs silently on the requests.get() call. The last visible log entry would be the debug message from the previous successful page fetch. No timeout error or exception is raised.
INFO - Starting sync stage 'gcp'
INFO - Syncing GCP Vertex AI models for project my-project
DEBUG - Fetching Vertex AI models from us-central1...
<process hangs here indefinitely — no further output>
Screenshots
N/A — This is a backend hang, not a UI issue.
Please complete the following information:
- Cartography release version or commit hash:
f0b8e89eedb516faf3ce691c278dad2fe7354693 - Python version: 3.13
- OS: Windows (reproducible on any OS)
Additional context
Suggested fix — Add timeout parameter:
_TIMEOUT = (60, 60) # (connect_timeout, read_timeout) — consistent with other modules
def list_all_resources_paginated(...):
# ... existing code ...
while True:
params: dict[str, str] = {}
if page_token:
params["pageToken"] = page_token
if session is not None:
response = session.get(url, headers=request_headers, params=params, timeout=_TIMEOUT)
else:
response = requests.get(url, headers=request_headers, params=params, timeout=_TIMEOUT)
Suggested fix — Add pagination safety limit:
The while True loop also lacks a maximum page counter. Consider adding a safety limit to prevent infinite pagination if the API misbehaves:
_MAX_PAGES = 1000
for page_num in range(_MAX_PAGES):
# ... existing pagination logic ...
page_token = data.get("nextPageToken")
if not page_token:
break
else:
logger.warning(
"Reached max page limit (%d) for %s in %s/%s — possible API issue",
_MAX_PAGES, resource_type, project_id, location,
)
Other modules for reference — The following modules correctly implement _TIMEOUT and can serve as patterns:
| Module | File | Timeout |
|---|---|---|
| BigFix | cartography/intel/bigfix/computers.py |
_TIMEOUT = 30 |
| GitHub | cartography/intel/github/util.py |
_TIMEOUT = (60, 60) |
| Semgrep | cartography/intel/semgrep/deployment.py |
_TIMEOUT = (60, 60) |
| Salesforce | cartography/intel/salesforce/util.py |
_TIMEOUT = 30 |
| Spacelift | cartography/intel/spacelift/util.py |
_TIMEOUT = (10, 30) |
The requests library documentation explicitly recommends: "You should nearly always set a timeout on outbound requests." — Python Requests: Timeouts
Hi @ajinkyap9 - can you please clarify: is this something you encountered while running cartography, or is it something theoretical?
Hello @achantavy, It was spotted during a review of HTTP patterns across the intel modules. Most other connectors (like GitHub, Semgrep, and Salesforce) enforce explicit _TIMEOUT values on outbound requests to guard against pipeline stalls, whereas the Vertex AI helper was missing one. While I didn't encounter a live hanging socket myself, adding the timeout ensures defensive handling if the endpoint ever freezes.