# Keep-alive and rotation

HTTP keep-alive lets a client send several requests over one TCP connection. Through a rotating proxy, the exit is chosen when the connection is opened, so every request reused on that connection leaves from the same IP. Clients that pool connections therefore see fewer IP changes than they expect; forcing a new connection per request restores per-request rotation.


## Symptoms

- An IP-echo call returns the same address several times in a row although no session id is set.
- A target that rate-limits per IP blocks a crawler that "rotates" but reuses a pool of ten connections.


## Fixes by client

| Client | How to get a new connection per request |
| --- | --- |
| cURL | each invocation is a new connection already |
| Python requests | requests.get(...) without a Session, or headers={"Connection": "close"} |
| Node.js fetch / undici | new ProxyAgent per request, or pipelining: 1 with keepAliveTimeout: 0 |
| Go net/http | Transport.DisableKeepAlives = true |
| Browsers | not controllable; use a sticky session instead and rotate by changing -sid- |


## The other way round

When you *want* one exit for several requests, keep-alive is your friend on the same connection, but do not rely on it: use a [sticky session](https://proxshift.com/glossary/sticky-session) so the guarantee survives connection resets.


## How it works at ProxShift

ProxShift gateways select the exit per new connection and keep it for the life of that connection (idle connections are closed after 60 seconds). -sid- makes the choice explicit and connection-independent.

Source: https://proxshift.com/glossary/keep-alive
