Skip to content

Cap the total time of a self-hosted proxy request - #130

Open
jonocodes wants to merge 1 commit into
mainfrom
fix/proxy-total-deadline
Open

jonocodes wants to merge 1 commit into
mainfrom
fix/proxy-total-deadline

Conversation

@jonocodes

Copy link
Copy Markdown
Owner

Follow-up to #125 (#124), from its code review.

The Node shell's guarded fetch had only an inactivity timeout (30 s). An upstream that sends a byte every few seconds never goes idle, so it could hold a socket, and the waiting client, open indefinitely.

Change

  • createGuardedFetch takes a new deadlineMs option, defaulting to 120 s, covering the whole exchange from request to the end of the body.
  • Before the response arrives, the deadline fails the request. After it arrives, the deadline destroys the body stream. That way the reason (upstream deadline timeout) reaches the reader, and core files it under its existing timeout error kind, instead of a generic aborted.
  • The timer is cleared when the body closes or the request errors, and it is unref'd.
  • infra/cors-worker/README.md documents both timeouts.

Tests

  • Two new tests in guarded-fetch.test.mjs:
    • An upstream that trickles one byte every 20 ms is cut off by the deadline. Without the fix this test hangs, so it was red first.
    • An upstream that never answers hits the deadline before the inactivity timeout.
  • node --test in infra/cors-worker: 103/103.

The Cloudflare shell is unaffected.

🤖 Generated with Claude Code

The Node shell's guarded fetch only had an inactivity timeout, so an
upstream sending a byte every few seconds could hold a socket open forever.
Add a 120 s deadline over the whole exchange; after the response starts it
destroys the body stream, so the reason ("deadline timeout") reaches the
core's log and its timeout classification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for savrlist ready!

Name Link
🔨 Latest commit 58e0ebd
🔍 Latest deploy log https://app.netlify.com/projects/savrlist/deploys/6ad7c4b1e3e30bd2683baa0e
😎 Deploy Preview https://deploy-preview-130--savrlist.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant