← Back to Pull requests

snigateway: pooled tunnel transport with PROXY protocol, session-scoped registration and failover #612

Closed
unknown closed this pull request without merging on Oct 04, 2026 21:16 UTC
View on GitHub
unknown unknown commented on Oct 04, 2026 19:43 UTC
Author

This PR implements a pooled reverse tunnel transport with PROXY protocol v2, session-scoped registrations, and failover for snigateway.

Summary of Changes

1. Transport Interface & Refactor:
- Introduced Transport and PoolTransport abstractions in pkg/frontend separating data-plane connections from the control plane.
2. Warm Pool of Pre-Dialed Reverse Tunnels & Session Registration:
- Replaced per-connection dial-back with a pool of $N$ pre-dialed reverse tunnels (configured via --tunnel-pool-size, default 4).
- Backend controllers establish long-lived sessions (GET /v1/session) and register hostnames (PUT /v1/registration with X-Session-ID). Multiple replicas sharing a certificate now register independent sessions without overwriting each other.
- Pool workers replenish connections immediately as idle tunnels are activated.
3. PROXY Protocol v2 Header:
- Implemented pkg/proxyproto for PROXY protocol v2 encoding and decoding with PP2_TYPE_AUTHORITY (0x02) TLV support for SNI hostnames.
- Frontend writes PROXY v2 header upon activating a pooled connection. Backend listener parses the header and wraps connections to expose real client IP addresses in RemoteAddr(), ensuring X-Forwarded-For propagation.
4. Health Checking, Failover, and Testing:
- Implemented replay-until-first-byte failover on the frontend. If a dead or unresponsive pooled connection fails before backend response bytes are received, the frontend drops the tunnel and replays the PROXY header + ClientHello to another healthy pooled connection.
- Enabled TCP keepalives on pooled connections.
- Added unit tests for PROXY v2 encoding/decoding, pool management, session registration, dead pooled connections, and unresponsive backend failover.
- Extended TestSNIGateway in snigateway/tests/e2e to run two controller replicas for the same hostname, kill one replica, and verify continuous request handling and real client IP forwarding.
- Updated docs/sni-reverse-tunnel.md and snigateway/README.md.

Fixes #607

Diff: 260 lines (+195 / -65) across 3 files Reviewer: justinsb Review duration: 93m
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 260 lines diff across 3 files
0.39
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.333
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #612"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 39.2% (MEDIUM) · Higher = larger blast radius
39.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 15.5% · Safe to merge
15.5%