Skip to main content

SKY-L031 · Logic and resilience

Missing network timeout

Medium

The catalog gives no severity for this rule; the detector always reports MEDIUM.

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

app/billing.py · PythonReported on line 9
"""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

app/billing.py · Python
"""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

  1. Runs with --quality on Python files. Skips test files: names that start with test_, end in _test.py, or are conftest.py.
  2. Matches the call by its written name: requests.get, post, put, patch, delete, head and options, the same seven under httpx., urllib.request.urlopen and a bare urlopen. Add names with extra_network_timeout_calls under [tool.skylos.vibe].
  3. Reports MEDIUM when the call has no timeout= keyword, or when it passes timeout=None. Any other timeout= value, even a variable, counts as a timeout.
  4. 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.

app/billing.py · Python · the fix, against the flagged file
"""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

  • httpx functions already apply a five-second default timeout, so an httpx.get(url) without timeout= does not hang forever; it is still reported.
  • A timeout passed through **kwargs, or as the third positional argument of urlopen(url, data, timeout), is not seen, and the call is reported.
  • Calls on a Session or httpx.Client, requests.request(...) and from requests import get are 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.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.