At 10:00, edge-7 points to upstream proxy A. A client connects through it and establishes a tunnel. At 10:01, the proxy list is replaced, and edge-7 now points to B. The client is still sending data at 10:02.
In SwitchTrace, a Rust-based local proxy relay and desktop application, aliases let clients keep a stable proxy configuration while upstream providers are changed behind it. Clients use HTTP CONNECT; after the relay establishes the upstream path, it forwards bytes in both directions.
The update at 10:01 must affect the next connection. It cannot change the upstream socket that the first connection is already using.
Resolve once, then keep the decision
HTTP CONNECT establishes a tunnel to the requested destination (RFC 9110, §9.3.6). Once that tunnel is established, the relay may be carrying an encrypted TLS session. There can be outstanding bytes, transport state and authentication tied to the upstream chosen during setup.
Switching the alias is a configuration change. Migrating an open TCP conversation to a different upstream would require handling state that the alias does not own and cannot transfer. If upstream A fails, the connection may fail with it; a new connection can resolve edge-7 to B.
The two lines represent connections created on opposite sides of a catalog replacement. They resolve the same alias, but the first already has a route to A. Only the new connection sees B.
The implementation hinges on the lifetime of the catalog lock. The active routing catalog can be protected by a short-lived read lock. During alias resolution, the connection takes a reference-counted handle to an immutable upstream definition. It releases the lock before performing network I/O. An administrative reload builds and validates a replacement catalog, acquires the write lock, swaps the catalog, then releases it.
The old definition remains allocated while the first connection holds a reference. That is the entire job of reference counting here. It does not keep A online, prevent the socket from failing, or preserve the client's TLS session if the upstream disappears.
Holding the read lock until the tunnel closes would create a different problem. A client could keep a connection open for hours and prevent a routing update for that entire period. Looking up the alias during each forwarding operation would be worse: one connection could observe multiple routing configurations even though its upstream TCP connection has not changed.
Constructing the replacement catalog before publication matters as well. A malformed entry or duplicate alias can be rejected without exposing a partially updated mapping to connection handlers. The published catalog is always a complete, validated snapshot.
What the short lock actually buys us
There are two separate ownership problems hiding in the word routing. The administrative side owns a changing lookup table. A connection handler owns the decision returned by one lookup. Those responsibilities overlap briefly and then separate.
A simplified version of the mechanism looks like this. The code is illustrative, not an excerpt from the private implementation:
// Configuration can change. A connection's resolved route should not.
fn resolve(&self, alias: &str) -> Option<Arc<Route>> {
let catalog = self.active.read().ok()?;
catalog.get(alias).cloned()
} // read guard released here
fn replace(&self, validated: Catalog) {
*self.active.write().expect("catalog lock") = validated;
}
The Arc<Route> clone preserves the lifetime of a particular route definition. Once resolve returns, the guard can be dropped. The connection then authenticates to its selected upstream and forwards traffic without consulting the catalog again.
This is not a lock-free design, and it doesn't need to be. Alias lookup is short. The expensive work—establishing a remote connection and moving bytes—happens after the lock is gone. A writer may briefly wait for an in-progress lookup, but it won't be blocked by a client that keeps a tunnel open all afternoon.
The replacement must itself be coherent. Building an alternative table entry by entry under a shared lock would make validation failures awkward, and building it in a sequence of independently visible edits would let readers see mixtures of old and new state. Instead, parse and validate the complete candidate first; publish it in one swap. The routing invariant is about which generation one lookup sees, not about whether every connection in the process uses the latest generation simultaneously.
This distinction is useful beyond networking. A request can take an immutable reference to a feature-policy snapshot; a query can pin a schema version; a worker can bind a task to a specific configuration revision. In all three cases, changing the global default should not rewrite decisions already in progress.
There is a cost. Old definitions are not reclaimed until their last holder releases them. If a deployment creates thousands of long-lived sessions across many configuration revisions, memory use can grow. Reference counting makes ownership safe; it doesn't provide a bound on how many historical revisions remain live. That must be observed separately.
An alias is a poor historical identifier
Suppose yesterday's connection record says that edge-7 timed out. Today, the alias points to B. If the history screen resolves that alias using the current catalog, yesterday's failure appears to belong to B even if A handled the connection.
For that reason, a connection record needs information captured at establishment time: the resolved upstream identity, the mapping revision, or both. Otherwise, the act of changing configuration changes the apparent meaning of older telemetry.
This is easy to miss if the application stores only an alias and assumes it can look up everything else later. That lookup is correct for present configuration and wrong for historical attribution.
What a CONNECT proxy can and cannot diagnose
The relay's visibility is also part of the design. An HTTP CONNECT request names a destination host and port; once the tunnel is established, application traffic may be TLS-encrypted. Without deliberately acting as a TLS-intercepting intermediary, the relay can measure connection setup, upstream handshake failures, duration, bytes forwarded and where the local socket encountered an error. It cannot reliably infer the full HTTPS path, the HTTP response code inside TLS, or whether the remote application accepted a user action.
For example, an upstream ECONNRESET is an observed transport event. Calling it a provider outage, a target-site rejection or an application failure requires other evidence. The diagnostic UI should keep those layers separate rather than assigning a single confident cause from a socket result.
The same principle applies to telemetry. In SwitchTrace, forwarding emits completion information through a bounded, non-blocking event path. When a writer falls behind, the relay has to choose what to protect. Making each connection await a database write would turn disk pressure into network latency. Dropping an event can leave the tunnel unaffected, but now historical reporting is incomplete.
That creates an easily missed statistical trap. Suppose a provider has 100 tunnel attempts and the telemetry writer saves only 90. A chart reporting 90 attempts has no way to recover the other 10 from those saved events alone. Worse, if pressure correlates with high connection churn, missing observations may be concentrated during the exact periods someone wants to investigate. Counting dropped events and writer lag outside the completion-event history is therefore necessary to know when a chart's denominator is suspect.
The principle isn't that telemetry should never block. It is that a component's backpressure policy must be selected consciously. In an offline billing ledger, dropping an event would be unacceptable. For a local relay's diagnostic stream, protecting the forwarding path and making loss visible is a reasonable tradeoff. A system that silently drops measurements and then presents precise-looking health rates has chosen the worst part of both approaches.
Testing the boundary
Two simple upstream servers are enough to exercise the behavior. Give them different responses so there is no ambiguity about which one handled traffic.
Start a long-lived tunnel when edge-7 points to A. Replace the catalog so the alias points to B. Send more traffic over the first tunnel, then open a second one. The first must continue using A; the second must use B. Removing the alias entirely from the new catalog adds another useful case: existing connections can finish, while subsequent resolutions fail.
The test also needs to check that the catalog reload completes while the old connection remains active. Otherwise, the implementation might have produced the correct route assignments by accidentally holding a lock for the entire connection lifetime.
Finally, inspect the two connection records. Each must retain the upstream identity and mapping revision it resolved when it began. If both records report B simply because B is the current mapping, the test should fail even though the byte forwarding succeeded.