SKY-L031 · Logic and resilience
Missing network timeout
requests waits for a server's answer as long as it takes unless you pass timeout=. SKY-L031 reports a requests, httpx or urlopen call made without a timeout, or with timeout=None.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
Why it matters
A server that accepts the connection and never answers holds the calling thread forever. In a web worker or a queue consumer, a few such calls use up every thread, and the whole service stops answering.
What Skylos flags
"""Fetch invoices from the payment provider.""" import requests API = "https://api.payments.example.com/v1" def fetch_invoice(session_token: str, invoice_id: str) -> dict: response = requests.get( f"{API}/invoices/{invoice_id}", headers={"Authorization": f"Bearer {session_token}"}, ) response.raise_for_status() return response.json()What Skylos leaves alone
"""Fetch invoices from the payment provider.""" import requests from app.settings import PAYMENTS_TIMEOUT API = "https://api.payments.example.com/v1" def fetch_invoice(session_token: str, invoice_id: str) -> dict: response = requests.get( f"{API}/invoices/{invoice_id}", headers={"Authorization": f"Bearer {session_token}"}, timeout=PAYMENTS_TIMEOUT, ) response.raise_for_status() return response.json()Why Skylos leaves it alone
The timeout comes from settings. Skylos cannot see its value, but any timeout= other than a literal None counts as a timeout.
How Skylos decides
- Runs with
--qualityon Python files. Skips test files: names that start withtest_, end in_test.py, or areconftest.py. - Matches the call by its written name:
requests.get,post,put,patch,delete,headandoptions, the same seven underhttpx.,urllib.request.urlopenand a bareurlopen. Add names withextra_network_timeout_callsunder[tool.skylos.vibe]. - Reports MEDIUM when the call has no
timeout=keyword, or when it passestimeout=None. Any othertimeout=value, even a variable, counts as a timeout. - The finding points at the line where the call starts.
How to fix it
Pass a timeout on every call. A (connect, read) pair lets a slow but working server finish while a dead one fails fast.
"""Fetch invoices from the payment provider.""" import requests API = "https://api.payments.example.com/v1" def fetch_invoice(session_token: str, invoice_id: str) -> dict: response = requests.get( f"{API}/invoices/{invoice_id}", headers={"Authorization": f"Bearer {session_token}"},Added: timeout=(3.05, 10), ) response.raise_for_status() return response.json()When it can be wrong
httpxfunctions already apply a five-second default timeout, so anhttpx.get(url)withouttimeout=does not hang forever; it is still reported.- A timeout passed through
**kwargs, or as the third positional argument ofurlopen(url, data, timeout), is not seen, and the call is reported. - Calls on a
Sessionorhttpx.Client,requests.request(...)andfrom requests import getare not checked at all.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Put the marker on the line where the call starts.
Python response = requests.get( # skylos: ignore[SKY-L031] timeout set by the adapter[tool.skylos] ignore = ["SKY-L031"]turns the rule off for the project.