Skip to content

Commit 1e7ebb1

Browse files
aherlihybehackett
authored andcommitted
PYTHON-933 - "maxPoolSize=0" allowed, causes hang.
1 parent ff3c18f commit 1e7ebb1

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

pymongo/common.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,25 @@ def validate_integer(option, value):
140140

141141

142142
def validate_positive_integer(option, value):
143-
"""Validate that 'value' is a positive integer.
143+
"""Validate that 'value' is a positive integer, which does not include 0.
144144
"""
145145
val = validate_integer(option, value)
146-
if val < 0:
146+
if val <= 0:
147147
raise ValueError("The value of %s must be "
148148
"a positive integer" % (option,))
149149
return val
150150

151151

152+
def validate_non_negative_integer(option, value):
153+
"""Validate that 'value' is a positive integer or 0.
154+
"""
155+
val = validate_integer(option, value)
156+
if val < 0:
157+
raise ValueError("The value of %s must be "
158+
"a non negative integer" % (option,))
159+
return val
160+
161+
152162
def validate_readable(option, value):
153163
"""Validates that 'value' is file-like and readable.
154164
"""
@@ -169,6 +179,14 @@ def validate_positive_integer_or_none(option, value):
169179
return validate_positive_integer(option, value)
170180

171181

182+
def validate_non_negative_integer_or_none(option, value):
183+
"""Validate that 'value' is a positive integer or 0 or None.
184+
"""
185+
if value is None:
186+
return value
187+
return validate_non_negative_integer(option, value)
188+
189+
172190
def validate_string(option, value):
173191
"""Validates that 'value' is an instance of `basestring` for Python 2
174192
or `str` for Python 3.
@@ -392,7 +410,7 @@ def validate_ok_for_update(update):
392410
'socketkeepalive': validate_boolean_or_string,
393411
'sockettimeoutms': validate_timeout_or_none,
394412
'waitqueuetimeoutms': validate_timeout_or_none,
395-
'waitqueuemultiple': validate_positive_integer_or_none,
413+
'waitqueuemultiple': validate_non_negative_integer_or_none,
396414
'ssl': validate_boolean_or_string,
397415
'ssl_keyfile': validate_readable,
398416
'ssl_certfile': validate_readable,

pymongo/mongo_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def __init__(
117117
- `maxPoolSize` (optional): The maximum number of connections
118118
that the pool will open simultaneously. If this is set, operations
119119
will block if there are `maxPoolSize` outstanding connections
120-
from the pool. Defaults to 100.
120+
from the pool. Defaults to 100. Cannot be 0.
121121
- `socketTimeoutMS`: (integer or None) Controls how long (in
122122
milliseconds) the driver will wait for a response after sending an
123123
ordinary (non-monitoring) database operation before concluding that

test/test_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ def test_types(self):
121121

122122
self.assertRaises(ConfigurationError, MongoClient, [])
123123

124+
def test_max_pool_size_zero(self):
125+
with self.assertRaises(ValueError):
126+
MongoClient(maxPoolSize=0)
127+
124128
def test_get_db(self):
125129
def make_db(base, name):
126130
return base[name]

test/test_pooling.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ def f():
428428
self.assertEqual(nthreads, self.n_passed)
429429
self.assertTrue(len(cx_pool.sockets) > 1)
430430

431+
def test_max_pool_size_zero(self):
432+
with self.assertRaises(ValueError):
433+
rs_or_single_client(maxPoolSize=0)
434+
431435
def test_max_pool_size_with_connection_failure(self):
432436
# The pool acquires its semaphore before attempting to connect; ensure
433437
# it releases the semaphore on connection failure.

0 commit comments

Comments
 (0)