Skip to content

hysteria transport: global QUIC client pool outlives core instance — connections with keepAlivePeriod never close after instance shutdown #7100

Closed
Jolymmiles/Xray-core
#30

Description

@lie-must-die

Summary

The hysteria transport keeps its QUIC clients in a process-global pool that is not tied to the Xray instance. When an instance is closed (e.g. core.Instance.Close() in an embedding app such as a mobile client that restarts the core on config change, or runs short-lived probe instances for latency tests), its hysteria QUIC connections are not closed. If finalmask.quicParams.keepAlivePeriod is set, those connections stay alive (sending keepalives) until the process exits.

Version

v26.9.9 (same code in v26.9.30). File: transport/internet/hysteria/dialer.go.

Details

  • dialer.go:289-292 — the pool is a package-level singleton (var manager *clientManager, initmanager sync.Once), created on first Dial (:303) and never reset.
  • dialer.go:268-271, 326 — the map key is dialerConf{net.Destination, *internet.MemoryStreamConfig}. Every new instance has its own *MemoryStreamConfig pointer, so every instance creates a new client for the same destination; entries from previous instances are never looked up again.
  • dialer.go:260-266, 278-287 — the cleanup goroutine (idleCleanupInterval = 1s) only closes a client whose conn.Context() is already done (StatusInactive). It never closes a live connection, and it never deletes entries from the map.
  • dialer.go:87-88 — MaxIdleTimeout / KeepAlivePeriod come from quicParams. With keepAlivePeriod: 20, maxIdleTimeout: 60, the idle timeout is never reached, so the orphaned connection lives forever.

Nothing in the instance shutdown path touches manager, so there is no way for an embedder to release these connections short of killing the process.

Impact

Observed in production on Android (gomobile/libv2ray, one long-lived process):

  • Each latency-test instance against a hysteria server leaves one QUIC connection alive after the instance is closed. After ~1 hour of normal use, conntrack on the server side showed 57 live UDP flows from a single phone, the oldest ~50 minutes old, all sending keepalives.
  • Wasted battery and mobile data; the server keeps per-connection state.
  • On some mobile networks many parallel QUIC flows to the same destination appear to trigger operator-side rate limiting, which then breaks new handshakes.
  • The map also grows without bound (one entry per instance × destination), retaining old MemoryStreamConfig objects.

Steps to reproduce

  1. Embed Xray, configure a hysteria outbound with finalmask.quicParams.keepAlivePeriod: 20.
  2. Start an instance, send one request through the outbound, then Close() the instance.
  3. Repeat N times in the same process.
  4. On the server (or with ss -uap / tcpdump on the client) observe N live QUIC connections that keep sending keepalive packets indefinitely.

Expected

Closing an instance closes all hysteria QUIC connections it created (as other transports' connections are closed when the instance's outbounds are closed).

Suggested fix

Either scope the client pool to the instance (e.g. hold it in a feature/object registered on the instance and close it from Close()), or track which clients belong to an instance and close + delete them on shutdown. At minimum, the cleanup loop should delete closed entries from the map.

Activity

  1. added a commit that references this issue on Oct 13, 2026
    647d464
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions