@@ -19,10 +19,31 @@ def __init__(self):
19
19
"""Create a Session object and set the is_good_response callback."""
20
20
super ().__init__ ()
21
21
22
+ # 'UnixAdapter` saves in the pool at most 'pool_connections'
23
+ # connections. When a new request is made, the adapter tries to match
24
+ # that request with an already existing connection from the pool, by
25
+ # comparing their url.
26
+ # If there's a match, then the adapter uses the connection from the
27
+ # pool to make the new request.
28
+ # Otherwise, a new connection is created and saved in the pool. If
29
+ # there is no space in the pool, the new connection will replace the
30
+ # least recently used one in the pool. The evicted connection will be
31
+ # closed.
32
+ #
22
33
# The `pool_connections` argument indicates the maximum number of
23
- # open connections allowed at a time. This value is set to 10 for
24
- # consistency with the micro-http's `MAX_CONNECTIONS`.
25
- self .mount (DEFAULT_SCHEME , UnixAdapter (pool_connections = 10 ))
34
+ # connection saved in the pool, not the maximum number of open
35
+ # connections allowed at the same time
36
+ # (see https://urllib3.readthedocs.io/en/stable/advanced-usage.html).
37
+ #
38
+ # We set this value to be equal to micro-http's `MAX_CONNECTIONS` - 1.
39
+ # This is because when reaching the `pool_connection` limit, it is not
40
+ # guaranteed that the event to close the connection will be received
41
+ # before the event that results in creating a new connection (this
42
+ # depends on the kernel). In case the two events are not received in
43
+ # the same order, or are received together, the server might try to add
44
+ # a new connection before removing the old one, resulting in a
45
+ # `SERVER_FULL_ERROR`.
46
+ self .mount (DEFAULT_SCHEME , UnixAdapter (pool_connections = 9 ))
26
47
27
48
def is_good_response (response : int ):
28
49
"""Return `True` for all HTTP 2xx response codes."""
0 commit comments