⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on Network monitoring, controls & Application development, testing, debugging.
2013-present by Abhinav Singh and contributors.
BSD, see LICENSE for more details.
- class proxy.core.connection.pool.UpstreamConnectionPool#
Manages connection pool to upstream servers.
UpstreamConnectionPoolavoids need to reconnect with the upstream servers repeatedly when a reusable connection is available in the pool.
A separate pool is maintained for each upstream server. So internally, it’s a pool of pools.
Internal data structure maintains references to connection objects that pool owns or has borrowed. Borrowed connections are marked as NOT reusable.
For reusable connections only, pool listens for read events to detect broken connections. This can happen if pool has opened a connection, which was never used and eventually reaches upstream server timeout limit.
When a borrowed connection is returned back to the pool, the connection is marked as reusable again. However, if returned connection has already been closed, it is removed from the internal data structure.
UpstreamConnectionPoolmust be shared across all cores to make SSL session cache to also work without additional out-of-bound synchronizations.
UpstreamConnectionPoolcurrently WON’T work for HTTPS connection. This is because of missing support for session cache, session ticket, abbr TLS handshake and other necessary features to make it work.
NOTE: However, currently for all HTTP only upstream connections,
UpstreamConnectionPoolcan be used to remove slow starts.
- _abc_impl = <_abc._abc_data object>#
- _add(conn: proxy.core.connection.server.TcpServerConnection) None #
Adds a new connection to internal data structure.
- acquire(addr: Tuple[str, int]) Tuple[bool, proxy.core.connection.server.TcpServerConnection] #
Returns a reusable connection from the pool.
If none exists, will create and return a new connection.
- add(addr: Tuple[str, int]) proxy.core.connection.server.TcpServerConnection #
Creates, connects and adds a new connection to the pool.
Returns newly created connection.
NOTE: You must not use the returned connection, instead use
- static create(*args: Any) proxy.core.connection.server.TcpServerConnection #
Implementations are responsible for creation of work objects from incoming args. This helps keep work core agnostic to creation of externally defined work class objects.
- async get_events() Dict[int, int] #
Returns read event flag for all reusable connections in the pool.
- async handle_events(readables: List[int], _writables: List[int]) bool #
Removes reusable connection from the pool.
When pool is the owner of connection, we don’t expect a read event from upstream server. A read event means either upstream closed the connection or connection has somehow reached an illegal state e.g. upstream sending data for previous connection acquisition lifecycle.
- release(conn: proxy.core.connection.server.TcpServerConnection) None #
Release a previously acquired connection.
Releasing a connection will shutdown and close the socket including internal pool cleanup.
- retain(conn: proxy.core.connection.server.TcpServerConnection) None #
Retained previously acquired connection in the pool for reusability.