Skip to content

Connection Pooling & Retries ## Business Purpose

Improve performance by reusing TCP connections and reduce transient failures by automatically retrying failed requests with configurable policies. ## Current Behaviors - HTTPAdapter.init_poolmanager creates a urllib3 PoolManager with configurable connections, maxsize, and block src/requests/adapters.py:239. - HTTPAdapter.__init__ sets max_retries to Retry(0, read=False) if DEFAULT_RETRIES is provided, else uses Retry.from_int(max_retries) src/requests/adapters.py:207. - The send method converts urllib3 MaxRetryError into specific exceptions like ConnectTimeout, RetryError, ProxyError, etc. src/requests/adapters.py:634. - get_connection_with_tls_context returns a connection from either a proxy manager or the poolmanager src/requests/adapters.py:403. - close clears the poolmanager and proxy managers src/requests/adapters.py:555. ## Technical Implementation The pool manager is lazily initialized in init_poolmanager. Retry policies are applied via urllib3's Retry object passed as max_retries to the pool manager. ## Definition of Done - Two requests to the same host reuse the same TCP connection (pooling). - Setting max_retries=2 results in up to 2 retries on HTTP 500 responses. - A connection pool exhaustion triggers ConnectionError. - Closing a session releases all pooled connections. - Retries on connection timeouts raise ConnectTimeout.