Skip to content

fix: update reverse_proxy.py to return correct status code for upstream request timeout - #210

Merged
alukach merged 2 commits into
mainfrom
lhoupert-patch-1
Sep 22, 2026
Merged

alukach merged 2 commits into
mainfrom
lhoupert-patch-1

Conversation

@lhoupert

@lhoupert lhoupert commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

closes #211

@github-actions github-actions Bot added the perf label Sep 18, 2026
@claude

claude Bot commented Sep 18, 2026

Copy link
Copy Markdown

Claude finished @lhoupert's task in 1m 21s —— View job


Review: reverse_proxy.py upstream timeout/connect-error handling

  • Gather context (diff, files)
  • Review reverse_proxy.py changes
  • Review test changes
  • Apply ponytail-review pass
  • Post final review

✅ No blocking issues — safe to merge.

The exception ordering is safe: httpx.ConnectTimeout is a subclass of httpx.TimeoutException, not of httpx.ConnectError, so the two except clauses are disjoint and always hit the intended branch. Tests cover both new paths with a MockTransport.

Non-blocking observations:

  • src/stac_auth_proxy/handlers/reverse_proxy.py:108-111 — every other error path in this codebase returns JSONResponse({"detail": ...}, status_code=...) (see Cql2BuildFilterMiddleware.py:106, EnforceAuthMiddleware.py:108). This handler instead returns a raw-text Response, so upstream-timeout/unreachable errors have a different body shape than other proxy errors, which could surprise STAC API clients that expect JSON error bodies. Consider matching the existing convention: JSONResponse({"detail": "Upstream timed out"}, status_code=504).
  • Only httpx.TimeoutException and httpx.ConnectError are caught. Other httpx.TransportError subclasses that can occur mid-request against a flaky upstream (ReadError, RemoteProtocolError, etc.) still propagate as unhandled exceptions → default 500. That may be intentional scope (matching issue Upstream timeout returns 500 instead of 504 #211), but worth confirming since it's the same class of failure (upstream instability) this PR is meant to guard against.

Fix this →

Simplify (ponytail)

Nothing to cut — the diff is a minimal try/except with two branches, no unnecessary abstraction.


💰 Estimated review cost: $0.30 · 1m21s · 15 turns

@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.68%. Comparing base (8b3d3c9) to head (64a9120).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #210      +/-   ##
==========================================
+ Coverage   89.65%   89.68%   +0.03%     
==========================================
  Files          30       30              
  Lines        1343     1348       +5     
  Branches      182      182              
==========================================
+ Hits         1204     1209       +5     
  Misses         97       97              
  Partials       42       42              
Flag Coverage Δ
unittests 89.68% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lhoupert
lhoupert requested a review from alukach September 18, 2026 13:41
The 504/502 branches added for upstream transport failures had no test
coverage, failing codecov/patch and codecov/project.

Drive them via an httpx.MockTransport that raises, and give the mock
request helper a receive channel so proxy_request can stream its body.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

@alukach alukach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix, thanks!

@alukach alukach changed the title perf: update reverse_proxy.py to return correct status code for upstream request timeout fix: update reverse_proxy.py to return correct status code for upstream request timeout Sep 22, 2026
@alukach
alukach merged commit be008ba into main Sep 22, 2026
13 checks passed
@alukach
alukach deleted the lhoupert-patch-1 branch September 22, 2026 20:44
@github-actions github-actions Bot added fix and removed perf labels Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upstream timeout returns 500 instead of 504

2 participants