Skip to content

fix(egress): retry a gateway CONNECT once on connection failure and log each failed attempt - #9351

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/egress-gateway-tunnel-retry
Oct 23, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
fix/egress-gateway-tunnel-retry

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • openGatewayTunnel retries the CONNECT once when it fails before a tunnel exists at the connection level (socket reset, TLS, connect timeout) or the proxy answers 5xx; no upstream bytes are sent before a 200, so the retry is safe
  • Each attempt opens a fresh undici Client, so the load balancer can pick another gateway task; each attempt keeps the existing CONNECT_TIMEOUT_MS (no new timeouts)
  • 4xx answers (407 credential, 403 admission) and UNSUPPORTED_TRANSPORT never retry
  • One logger.warn per failed attempt with gateway id, organization id, attempt, proxy status code, and error name/code; no token, CA, or gateway URL is logged
  • The thrown error stays GATEWAY_UNAVAILABLE, so callers and user-facing messages are unchanged
  • Both the pinned and DNS-guarded fetch paths reach the tunnel through createGatewayDispatcher, so one retry covers both; nothing above it retries OutboundRoutingError, and undici's connector exposes no request signal to plumb

Type of Change

  • Bug fix

Testing

  • gateway.server.test.ts (real TLS CONNECT proxy) gains three cases: a dropped first CONNECT recovers on the second and the request succeeds; a 407 fails after exactly one attempt; a reset then a 503 fails after exactly two attempts
  • Red check: the first and third fail on the pre-change code; the 407 case fails when the retry is made unconditional
  • vitest run lib/core/network/ (60 passed), biome, check:explicit-any, check:comment-hygiene, check:utils; CI runs the rest

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 23, 2026 10:41pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues remain.

Summary

Adds one retry for gateway CONNECT failures and logs each failed attempt without logging credentials.

  • Gateway requests retry a failed CONNECT once.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Open fresh gateway client] --> B{CONNECT result}
  B -->|200| C[Return tunnel]
  B -->|Failure| D[Log failed attempt]
  D --> E{Connection failure or 5xx?}
  E -->|Yes, first attempt| A
  E -->|No, or second attempt| F[Throw GATEWAY_UNAVAILABLE]
Loading

Reviews (2) · Last reviewed commit: "test(egress): cover the 5xx CONNECT retr..." · Reviewed by Greptile

Comment thread apps/sim/lib/core/network/gateway.server.test.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 772fcf7 into staging Oct 23, 2026
67 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/egress-gateway-tunnel-retry branch October 23, 2026 23:29

This branch was previously deployed

1 inactive deployment
Preview — 68a7bb1e Deployed Oct 23, 2026 by vercel[bot]
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