How to Test Proxy Keep-Alive Without Breaking IP Rotation

Connection reuse can make a proxy-backed collector faster and cheaper. It can also quietly defeat per-connection rotation, preserve a bad route, or make a configuration change appear ineffective because the client keeps using an old socket. The right question is therefore not “Should keep-alive be enabled?” It is “Which identity boundary may reuse which connection, for how long, and with what evidence?”

This guide provides a repeatable test for residential, rotating, static residential, HTTP(S), and SOCKS5 proxy workflows used for authorized data collection, market research, ad verification, localization QA, and regression testing.

Ceramic Internet map showing persistent and newly opened proxy routes

Separate four things that are often called a session

Before testing, name each layer precisely:

  1. Application job: one search, page journey, or validation unit.
  2. Proxy session: the provider-side label or credential that requests a sticky exit.
  3. Transport connection: the TCP or QUIC connection between client and proxy gateway.
  4. Origin connection: the gateway-to-destination connection, which the provider may manage independently.

An application can start a new request while reusing the same transport connection. A “rotating” gateway may choose a new exit per connection rather than per request. Conversely, a sticky session may survive several transport reconnections. If those units are mixed together, rotation results become impossible to interpret.

Define the expected identity contract

Write the rule before running the test. Examples:

  • Independent stateless jobs should receive a fresh exit when a fresh proxy connection is opened.
  • Every step in one authorized multi-page workflow should keep the same country and exit identity.
  • Unrelated users or jobs must never share cookies, proxy-session labels, or connection pools.
  • A proxy configuration change must not reuse a socket created under the old configuration.

Use tokenized identifiers in logs. Never store proxy passwords, cookies, authorization headers, or complete personal data in the evidence set.

Build a two-by-two experiment

Run the same permitted target and payload under four modes:

ModeProxy sessionClient connection poolPurpose
ArotatingdisabledEstablish fresh-connection behavior
BrotatingenabledDetect whether reuse pins the exit
CstickydisabledProve provider-side stickiness survives reconnects
DstickyenabledMeasure the fastest valid journey path

Keep region, target, headers, body validation, timeout, and request count fixed. Use at least 30 completed requests per mode and repeat across several time windows. One short burst cannot distinguish an intentional sticky policy from limited regional inventory.

Record connection-level evidence

For every request capture only the minimum operational fields:

  • job number and tokenized session label;
  • whether the client reused a connection;
  • connection age and requests already carried;
  • expected and observed region;
  • tokenized exit fingerprint;
  • proxy authentication outcome;
  • connect, TLS, first-byte, and total time;
  • response class and content-validation result;
  • bytes transferred;
  • whether a retry used the same or a fresh connection.

Do not treat HTTP 200 as success until the expected content, locale, freshness, and completeness have been validated.

Prove whether keep-alive changes rotation

Compare unique exit fingerprints by request and by new connection. If mode A rotates while mode B remains on one exit, the rotation boundary is probably the transport connection. That is not automatically a defect; it means the pool policy must match the job’s identity contract.

Useful measures include:

reuse_ratio = reused_requests / completed_requests
rotation_per_connection = unique_exits / new_proxy_connections
valid_throughput = valid_results / elapsed_minutes
cost_per_valid_result = transferred_cost / valid_results

The preferred mode is the one that satisfies the identity contract with the lowest p95 latency and cost per valid result—not necessarily the one with the most unique IPs.

Detect stale pooled sockets

An idle connection can outlive a gateway route, NAT mapping, proxy-session lease, or intermediate timeout. A stale socket often fails on its first reuse, then succeeds immediately on a fresh connection. Test this deliberately with idle gaps such as 15, 30, 60, and 120 seconds.

Classify these cases separately:

  • failure before proxy authentication;
  • explicit proxy authentication rejection;
  • reset on the first write after idle;
  • timeout after the request reached the proxy;
  • destination rejection or rate limit;
  • valid status with wrong or incomplete content.

If failures cluster on the first reused request after an idle gap, shorten the idle lifetime or validate pooled sockets before assigning valuable work. Do not label the entire proxy pool unhealthy.

Bound the pool instead of maximizing it

Set separate limits for live connections, idle connections, connection age, requests per connection, and queue age. A large unbounded pool creates more sockets than it can use, consumes file descriptors, and makes it harder to drain an old configuration.

A safe rollout normally includes:

  • a per-destination pool rather than one global pool;
  • a separate pool for each identity or sticky-session boundary;
  • a maximum idle time below the first observed stale-socket cliff;
  • a maximum connection age so configuration and DNS changes eventually take effect;
  • a bounded queue that rejects or delays work before saturation;
  • a small retry budget that prefers a fresh connection after a connection-level failure.

Never retry every error on the same pooled socket. Never open a new connection for every retry without a cap, either; that can turn a short outage into a connection storm.

Validate configuration changes with a drain test

When changing proxy endpoints, credentials, regions, or rotation modes, stop admitting new work to the old pool. Allow safe in-flight jobs to finish, close idle connections, then create a fresh client or transport pool. Verify that the new connection uses the expected proxy route before increasing traffic.

This drain test also detects direct-connection leakage. A required proxy failure must fail closed; it must not silently reuse a direct socket or fall back to the device network.

Choose production acceptance gates

A candidate configuration should pass all of these:

  • the exit behavior matches the written job identity contract;
  • no cookies or session state cross unrelated jobs;
  • first-attempt valid-result rate stays within the service objective;
  • p95 latency improves without increasing incomplete responses;
  • stale-socket failures remain below the error budget;
  • retries do not increase total offered load during an incident;
  • proxy changes take effect after a controlled drain;
  • direct-path leakage tests remain at zero;
  • cost per valid result improves or remains justified.

Start with a small production canary and keep the old pool settings available for rollback.

Checklist

  • Define request, connection, proxy-session, and job boundaries.
  • Test rotating and sticky behavior with pooling both on and off.
  • Validate content rather than trusting status codes.
  • Measure exit changes per new connection.
  • Add controlled idle gaps to expose stale sockets.
  • Separate connection failures from destination failures.
  • Bound idle count, age, requests per connection, and queue age.
  • Drain old pools after proxy configuration changes.
  • Retry connection failures on a fresh socket within a strict budget.
  • Keep credentials and user data out of logs.

FAQ

Does keep-alive always prevent proxy rotation?

No. It depends on the provider and protocol. Some gateways rotate per connection, some use a proxy-session label, and some apply other policies. Measure the behavior of the actual plan and client stack.

Should a rotating residential proxy open a new connection for every request?

Only if each request is independent and the identity contract requires a new exit. Multi-step journeys usually need continuity, while excessive reconnects add handshakes, latency, and failure opportunities.

Is a new exit proof that the old one was bad?

No. A different exit only proves that routing changed. Compare valid results, latency, geography, and cost before judging quality.

What should be retried after a stale connection fails?

Retry only safe, idempotent work, use a fresh connection, add jitter, and enforce a small retry budget. Do not replay non-idempotent actions automatically.

Compliance note

Use proxies and automation only for systems and data you are authorized to access. Respect destination terms, access policies, rate limits, privacy obligations, regional law, and data-retention requirements. Connection reuse and rotation must not be used to evade controls.

Continue with the residential proxy session-stickiness test, the proxy retry-budget guide, and the direct-fallback leak test.