[GH-ISSUE #5314] [Feature]: Auto-rotate Reality SNI/dest on probe failure with live apply #3724

Open
opened 2026-10-31 20:34:30 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Ssentiago on GitHub (Jun 14, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5314

Yes. When a Reality dest/SNI target becomes unavailable — blocked by IP, domain suspended, or the host stops supporting TLS 1.3/H2 — the inbound stops working for all clients simultaneously. The only recovery is manual: admin notices the outage, finds a new working target, updates the inbound in the panel UI. During this window all clients are down.

Describe the solution you'd like

A fallback SNI list per Reality inbound with automatic health-based switching:

  1. Admin specifies an ordered list of dest/SNI pairs as fallback candidates in the inbound settings
  2. 3x-ui backend periodically probes the current dest (TCP handshake to port 443, or full TLS check)
  3. If the probe fails or exceeds a configurable latency threshold N times in a row — backend patches the inbound config to the next candidate and applies it live via the Xray gRPC API (no core restart, existing connections survive — same mechanism introduced in v3.3.x)
  4. A cooldown period prevents flapping on transient spikes
  5. Current active SNI and last probe result are visible in the inbound list UI
  6. Telegram bot notification on SNI switch (panel already has bot integration)

Config fields needed:

  • sni_fallback_list: ordered list of dest:port + sni pairs
  • probe_interval_sec: how often to probe (default: 60)
  • probe_timeout_ms: threshold to consider degraded (default: 3000)
  • fail_threshold: consecutive failures before switching (default: 3)
  • cooldown_sec: minimum time between switches (default: 300)

Alternatives you've considered

Multiple inbounds with different SNIs — requires clients to have multiple configs and handle failover themselves; not viable for managed deployments where clients are non-technical

Concrete use case

A Reality+VLESS inbound is running with a single dest/SNI target. The target host becomes unreachable from the server's network (IP blocked, domain suspended, or TLS 1.3/H2 support dropped). All connected clients lose connectivity simultaneously. Admin has to manually find a working replacement target via RealiTLScanner, update the inbound, restart xray — typically 30–60 minutes of downtime.
With this feature: probe detects the failure within probe_interval * fail_threshold seconds, automatically switches to the next candidate in the fallback list, applies the change live without interrupting existing connections. Downtime drops to under a minute with zero admin intervention.

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

No response

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @Ssentiago on GitHub (Jun 14, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5314 ### Is your feature request related to a problem? Yes. When a Reality dest/SNI target becomes unavailable — blocked by IP, domain suspended, or the host stops supporting TLS 1.3/H2 — the inbound stops working for all clients simultaneously. The only recovery is manual: admin notices the outage, finds a new working target, updates the inbound in the panel UI. During this window all clients are down. ### Describe the solution you'd like A fallback SNI list per Reality inbound with automatic health-based switching: 1. Admin specifies an ordered list of dest/SNI pairs as fallback candidates in the inbound settings 2. 3x-ui backend periodically probes the current dest (TCP handshake to port 443, or full TLS check) 3. If the probe fails or exceeds a configurable latency threshold N times in a row — backend patches the inbound config to the next candidate and applies it live via the Xray gRPC API (no core restart, existing connections survive — same mechanism introduced in v3.3.x) 4. A cooldown period prevents flapping on transient spikes 5. Current active SNI and last probe result are visible in the inbound list UI 6. Telegram bot notification on SNI switch (panel already has bot integration) Config fields needed: - sni_fallback_list: ordered list of dest:port + sni pairs - probe_interval_sec: how often to probe (default: 60) - probe_timeout_ms: threshold to consider degraded (default: 3000) - fail_threshold: consecutive failures before switching (default: 3) - cooldown_sec: minimum time between switches (default: 300) ### Alternatives you've considered Multiple inbounds with different SNIs — requires clients to have multiple configs and handle failover themselves; not viable for managed deployments where clients are non-technical ### Concrete use case A Reality+VLESS inbound is running with a single dest/SNI target. The target host becomes unreachable from the server's network (IP blocked, domain suspended, or TLS 1.3/H2 support dropped). All connected clients lose connectivity simultaneously. Admin has to manually find a working replacement target via RealiTLScanner, update the inbound, restart xray — typically 30–60 minutes of downtime. With this feature: probe detects the failure within probe_interval * fail_threshold seconds, automatically switches to the next candidate in the fallback list, applies the change live without interrupting existing connections. Downtime drops to under a minute with zero admin intervention. ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? _No response_ ### Are you willing to help? - [x] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@github-actions[bot] commented on GitHub (Jun 14, 2026):

This is a well-scoped request. Below is a technical assessment based on the current source, written to help you get a PR to a mergeable state.


Existing infrastructure you can build on

Piece Location in source
Hot-apply inbound change (del + re-add via gRPC, no process restart) internal/web/service/xray.go:tryHotApply, internal/xray/hot_diff.go
XrayAPI.DelInbound / AddInbound gRPC wrappers internal/xray/api.go:120–148
InboundService.UpdateInbound (persists to DB and triggers reload) internal/web/service/inbound.go:928
Periodic job pattern (cron, same signature as existing jobs) internal/web/job/outbound_subscription_job.go, check_xray_running_job.go
Outbound TCP/HTTP probe infrastructure (dial + TLS timing) internal/web/service/outbound/probe_http.go
Telegram admin broadcast internal/web/service/tgbot/tgbot_send.go:SendMsgToTgbotAdmins
Reality stream settings schema (frontend Zod) frontend/src/schemas/protocols/security/reality.ts
Reality form UI frontend/src/pages/inbounds/form/security/reality.tsx

The hot-apply path (tryHotApply) was introduced in the v3.3.x series (latest release is v3.3.1). A Reality-target change is a StreamSettings mutation on an existing inbound, which falls into the remove-then-re-add path inside diffInbounds (hot_diff.go:102–134). This means the xray process does not restart, but the inbound handler is replaced — any TCP sessions that were open on that inbound at the moment of the switch are dropped. This is meaningfully better than a full process restart (no disruption to other inbounds), but the request's claim that "existing connections survive" needs to be narrowed to "connections on other inbounds survive."


Reality field mapping you need to be aware of

In frontend/src/schemas/protocols/security/reality.ts:

  • target — the dest host Reality connects to for its TLS handshake (e.g. www.amazon.com:443). This is what a failover must update.
  • serverNames — an array of SNI values clients are allowed to present. For correct failover you also need to update settings.serverName (the client-side SNI hint stored under realitySettings.settings.serverName) to match the new target, otherwise newly-generated share links will carry the old SNI.

A fallback candidate must therefore carry both a target and a matching serverName; the existing RealityTarget type in frontend/src/models/reality-targets.ts already models exactly this pair.


Probe implementation note

For Reality you need TLS 1.3 + H2 to be available at the target; a plain TCP dial to port 443 only tests reachability, not TLS 1.3/ALPN support. A more correct probe connects with a TLS 1.3-only dial and checks ConnectionState().NegotiatedProtocol for h2. The existing outbound prober in internal/web/service/outbound/probe_http.go handles TCP dial and full HTTP-through-SOCKS but does not do a TLS handshake health check, so this would be new code.


Schema / migration requirements

The Inbound model (internal/database/model/model.go:46) has no fields for fallback state. You would need to either:

  • add columns to the Inbound table (reality_fallback_list TEXT, reality_active_idx INT DEFAULT 0, etc.), or
  • use a separate table keyed on inbound_id.

Either way a GORM auto-migration entry in internal/database/ is required. Inspect the existing migration pattern before adding columns to understand the ordering constraints.


Suggested implementation checklist for a PR

  1. New fields on Inbound (or a linked table) + migration — fallback list, active index, probe config, probe state (consecutive failures, last switch time).
  2. New periodic job in internal/web/job/ following the OutboundSubscriptionJob pattern — loads inbounds with Reality + fallback configured, probes current target, updates DB + triggers hot-apply on threshold breach.
  3. Proper TLS 1.3 + H2 probe function (not plain TCP dial) — can live alongside internal/web/service/outbound/probe_http.go or in a new file under internal/web/service/.
  4. Telegram notification on switch via Tgbot.SendMsgToTgbotAdmins.
  5. Frontend: extend RealityStreamSettingsSchema with the new fields, add ordered-list UI in frontend/src/pages/inbounds/form/security/reality.tsx, expose active SNI and last-probe status in the inbound list.
  6. Unit tests for the probe logic and the failover state machine.

The maintainers will have the final say on API surface and DB schema; it is worth opening a draft PR early to get feedback before sinking time into the UI layer.


This reply was generated automatically; a maintainer may follow up with additional guidance.

<!-- gh-comment-id:4701566341 --> @github-actions[bot] commented on GitHub (Jun 14, 2026): This is a well-scoped request. Below is a technical assessment based on the current source, written to help you get a PR to a mergeable state. --- **Existing infrastructure you can build on** | Piece | Location in source | |---|---| | Hot-apply inbound change (del + re-add via gRPC, no process restart) | `internal/web/service/xray.go:tryHotApply`, `internal/xray/hot_diff.go` | | `XrayAPI.DelInbound` / `AddInbound` gRPC wrappers | `internal/xray/api.go:120–148` | | `InboundService.UpdateInbound` (persists to DB and triggers reload) | `internal/web/service/inbound.go:928` | | Periodic job pattern (cron, same signature as existing jobs) | `internal/web/job/outbound_subscription_job.go`, `check_xray_running_job.go` | | Outbound TCP/HTTP probe infrastructure (dial + TLS timing) | `internal/web/service/outbound/probe_http.go` | | Telegram admin broadcast | `internal/web/service/tgbot/tgbot_send.go:SendMsgToTgbotAdmins` | | Reality stream settings schema (frontend Zod) | `frontend/src/schemas/protocols/security/reality.ts` | | Reality form UI | `frontend/src/pages/inbounds/form/security/reality.tsx` | The hot-apply path (`tryHotApply`) was introduced in the v3.3.x series (latest release is v3.3.1). A Reality-target change is a `StreamSettings` mutation on an existing inbound, which falls into the remove-then-re-add path inside `diffInbounds` (`hot_diff.go:102–134`). This means the xray process does not restart, but the inbound handler is replaced — any TCP sessions that were open on that inbound at the moment of the switch are dropped. This is meaningfully better than a full process restart (no disruption to other inbounds), but the request's claim that "existing connections survive" needs to be narrowed to "connections on other inbounds survive." --- **Reality field mapping you need to be aware of** In `frontend/src/schemas/protocols/security/reality.ts`: - `target` — the dest host Reality connects to for its TLS handshake (e.g. `www.amazon.com:443`). This is what a failover must update. - `serverNames` — an array of SNI values clients are allowed to present. For correct failover you also need to update `settings.serverName` (the client-side SNI hint stored under `realitySettings.settings.serverName`) to match the new target, otherwise newly-generated share links will carry the old SNI. A fallback candidate must therefore carry **both** a `target` and a matching `serverName`; the existing `RealityTarget` type in `frontend/src/models/reality-targets.ts` already models exactly this pair. --- **Probe implementation note** For Reality you need TLS 1.3 + H2 to be available at the target; a plain TCP dial to port 443 only tests reachability, not TLS 1.3/ALPN support. A more correct probe connects with a TLS 1.3-only dial and checks `ConnectionState().NegotiatedProtocol` for `h2`. The existing outbound prober in `internal/web/service/outbound/probe_http.go` handles TCP dial and full HTTP-through-SOCKS but does not do a TLS handshake health check, so this would be new code. --- **Schema / migration requirements** The `Inbound` model (`internal/database/model/model.go:46`) has no fields for fallback state. You would need to either: - add columns to the `Inbound` table (`reality_fallback_list TEXT`, `reality_active_idx INT DEFAULT 0`, etc.), or - use a separate table keyed on `inbound_id`. Either way a GORM auto-migration entry in `internal/database/` is required. Inspect the existing migration pattern before adding columns to understand the ordering constraints. --- **Suggested implementation checklist for a PR** 1. New fields on `Inbound` (or a linked table) + migration — fallback list, active index, probe config, probe state (consecutive failures, last switch time). 2. New periodic job in `internal/web/job/` following the `OutboundSubscriptionJob` pattern — loads inbounds with Reality + fallback configured, probes current target, updates DB + triggers hot-apply on threshold breach. 3. Proper TLS 1.3 + H2 probe function (not plain TCP dial) — can live alongside `internal/web/service/outbound/probe_http.go` or in a new file under `internal/web/service/`. 4. Telegram notification on switch via `Tgbot.SendMsgToTgbotAdmins`. 5. Frontend: extend `RealityStreamSettingsSchema` with the new fields, add ordered-list UI in `frontend/src/pages/inbounds/form/security/reality.tsx`, expose active SNI and last-probe status in the inbound list. 6. Unit tests for the probe logic and the failover state machine. The maintainers will have the final say on API surface and DB schema; it is worth opening a draft PR early to get feedback before sinking time into the UI layer. --- *This reply was generated automatically; a maintainer may follow up with additional guidance.*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3724
No description provided.