Skip to content

Commit d77cb67

Browse files
authored
PYTHON-2717 Treat maxPoolSize=0 the same as maxPoolSize=None
1 parent 11e6f98 commit d77cb67

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

pymongo/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ def validate_tzinfo(dummy, value):
607607
'journal': validate_boolean_or_string,
608608
'localthresholdms': validate_positive_float_or_zero,
609609
'maxidletimems': validate_timeout_or_none,
610-
'maxpoolsize': validate_positive_integer_or_none,
610+
'maxpoolsize': validate_non_negative_integer_or_none,
611611
'maxstalenessseconds': validate_max_staleness,
612612
'readconcernlevel': validate_string_or_none,
613613
'readpreference': validate_read_preference_mode,

pymongo/mongo_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ def __init__(
207207
- `maxPoolSize` (optional): The maximum allowable number of
208208
concurrent connections to each connected server. Requests to a
209209
server will block if there are `maxPoolSize` outstanding
210-
connections to the requested server. Defaults to 100. Cannot be 0.
210+
connections to the requested server. Defaults to 100. Can be
211+
either 0 or None, in which case there is no limit on the number
212+
of concurrent connections.
211213
- `minPoolSize` (optional): The minimum required number of concurrent
212214
connections that the pool will maintain to each connected server.
213215
Default is 0.
@@ -1004,7 +1006,8 @@ def max_pool_size(self):
10041006
"""The maximum allowable number of concurrent connections to each
10051007
connected server. Requests to a server will block if there are
10061008
`maxPoolSize` outstanding connections to the requested server.
1007-
Defaults to 100. Cannot be 0.
1009+
Defaults to 100. Can be either 0 or None, in which case there is no
1010+
limit on the number of concurrent connections.
10081011
10091012
When a server's pool has reached `max_pool_size`, operations for that
10101013
server block waiting for a socket to be returned to the pool. If

pymongo/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ def __init__(self, address, options, handshake=True):
11321132
self.size_cond = threading.Condition(self.lock)
11331133
self.requests = 0
11341134
self.max_pool_size = self.opts.max_pool_size
1135-
if self.max_pool_size is None:
1135+
if not self.max_pool_size:
11361136
self.max_pool_size = float('inf')
11371137
# The second portion of the wait queue.
11381138
# Enforces: maxConnecting

test/test_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ def test_types(self):
161161
self.assertRaises(ConfigurationError, MongoClient, [])
162162

163163
def test_max_pool_size_zero(self):
164-
with self.assertRaises(ValueError):
165-
MongoClient(maxPoolSize=0)
164+
MongoClient(maxPoolSize=0)
166165

167166
def test_uri_detection(self):
168167
self.assertRaises(

test/test_pooling.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,14 @@ def f():
485485
joinall(threads)
486486
self.assertEqual(nthreads, self.n_passed)
487487
self.assertTrue(len(cx_pool.sockets) > 1)
488+
self.assertEqual(cx_pool.max_pool_size, float('inf'))
489+
488490

489491
def test_max_pool_size_zero(self):
490-
with self.assertRaises(ValueError):
491-
rs_or_single_client(maxPoolSize=0)
492+
c = rs_or_single_client(maxPoolSize=0)
493+
self.addCleanup(c.close)
494+
pool = get_pool(c)
495+
self.assertEqual(pool.max_pool_size, float('inf'))
492496

493497
def test_max_pool_size_with_connection_failure(self):
494498
# The pool acquires its semaphore before attempting to connect; ensure

test/uri_options/connection-pool-options.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@
3131
"auth": null,
3232
"options": {}
3333
},
34+
{
35+
"description": "maxPoolSize=0 does not error",
36+
"uri": "mongodb://example.com/?maxPoolSize=0",
37+
"valid": true,
38+
"warning": false,
39+
"hosts": null,
40+
"auth": null,
41+
"options": {
42+
"maxPoolSize": 0
43+
}
44+
},
3445
{
3546
"description": "minPoolSize=0 does not error",
3647
"uri": "mongodb://example.com/?minPoolSize=0",

0 commit comments

Comments
 (0)