FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(ws): add an upgrade establishment timeout by DavidIlie · Pull Request #172 · unjs/httpxy · GitHub

Repository navigation

feat(ws): add an upgrade establishment timeout - #172

Open
DavidIlie wants to merge 1 commit into
unjs:mainfrom
DavidIlie:codex/ws-establishment-deadline
Open

DavidIlie wants to merge 1 commit into
unjs:mainfrom
DavidIlie:codex/ws-establishment-deadline

Conversation

DavidIlie commented Sep 10, 2026 •
edited by coderabbitai Bot
Loading

Copy link
Copy Markdown

Summary

Adds optional establishmentTimeout support to proxyUpgrade and ProxyServer.ws().

The deadline covers connection setup through upstream upgrade or final response headers. It is disabled by default and does not limit established tunnels or non-upgrade response bodies.

Timeouts report ERR_UPSTREAM_UPGRADE_TIMEOUT with statusCode: 504 and destroy the pending upstream request and client socket without writing an HTTP 504 response. Failure is reported even when a custom agent is waiting for a socket. Downstream cancellation preserves the original error where available, and deferred request errors do not cause duplicate delivery.

Verification

  • pnpm vitest run test/ws-timeout.test.ts
  • pnpm test
  • pnpm build
  • Focused tests pass on Node 24.11.1 and 26.5.0.
  • Regression coverage includes saturated agents, cancellation, error-listener behavior, late agent release, and established tunnels surviving beyond the deadline.

Summary by CodeRabbit

  • New Features

    • Added an optional WebSocket establishment timeout for proxy upgrades.
    • Configurable deadlines now cover receiving upstream response headers or a successful upgrade.
    • Timeout failures report a 504 error and clean up affected connections.
    • Invalid, non-positive, or non-finite values disable the deadline.
  • Documentation

    • Added configuration guidance, behavior details, and examples for the new timeout option.

coderabbitai Bot commented Sep 10, 2026 •
edited
Loading

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info ⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: faf12e7e-683c-430a-b763-9f12f1e968e3

📥 Commits

Reviewing files that changed from the base of the PR and between 54e4263 and 60932bf.

📒 Files selected for processing (8)
  • AGENTS.md
  • README.md
  • src/_ws-timeout.ts
  • src/middleware/ws-incoming.ts
  • src/types.ts
  • src/ws.ts
  • test/types.test-d.ts
  • test/ws-timeout.test.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The PR adds an optional establishmentTimeout to WebSocket proxy APIs. It enforces the deadline for upstream response headers or upgrades, cleans up timed-out connections, updates documentation and types, and adds coverage for timeout, cancellation, agent, response, and invalid-value behavior.

Changes

WebSocket establishment timeout

Layer / File(s) Summary
Timeout option and documented contract
src/types.ts, src/ws.ts, README.md, AGENTS.md, test/types.test-d.ts
Adds establishmentTimeout to both public option types and documents disabled values, the timeout cap, error details, cleanup, and cancellation behavior.
Timeout enforcement and error handling
src/_ws-timeout.ts, src/ws.ts, src/middleware/ws-incoming.ts
Adds the timeout helper and wires it into both proxy paths. The helper clears listeners after settlement and destroys timed-out requests and sockets.
Timeout behavior validation
test/ws-timeout.test.ts
Tests timeout expiry, cleanup, queued-agent handling, downstream cancellation, successful upgrades, non-upgrade responses, upstream errors, and invalid values.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Proxy
  participant TimeoutHelper
  participant Upstream
  Client->>Proxy: request WebSocket upgrade
  Proxy->>TimeoutHelper: setUpgradeTimeout
  TimeoutHelper->>Upstream: monitor upgrade request and socket
  Upstream-->>TimeoutHelper: response, upgrade, error, or close
  TimeoutHelper-->>Proxy: report timeout or socket failure
  Proxy-->>Client: close or complete connection
Loading

Suggested reviewers: pi0

Merge Risk: ⚪ Minimal · up to 60932

The opt-in WebSocket establishment timeout is typed, documented, enforced across both proxy paths, and covered for timeout, cleanup, cancellation, and successful establishment behavior.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 6 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding an establishment timeout for WebSocket upgrades.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 6 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

DavidIlie marked this pull request as ready for review September 18, 2026 10:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL