PYTHON-933 - "maxPoolSize=0" allowed, causes hang
This commit is contained in:
parent
e405ef91cf
commit
5ffe8d44bc
@ -98,12 +98,22 @@ def validate_integer(option, value):
|
||||
|
||||
|
||||
def validate_positive_integer(option, value):
|
||||
"""Validate that 'value' is a positive integer.
|
||||
"""Validate that 'value' is a positive integer, which does not include 0.
|
||||
"""
|
||||
val = validate_integer(option, value)
|
||||
if val <= 0:
|
||||
raise ConfigurationError("The value of %s must be "
|
||||
"a positive integer" % (option,))
|
||||
return val
|
||||
|
||||
|
||||
def validate_non_negative_integer(option, value):
|
||||
"""Validate that 'value' is a positive integer or 0.
|
||||
"""
|
||||
val = validate_integer(option, value)
|
||||
if val < 0:
|
||||
raise ConfigurationError("The value of %s must be "
|
||||
"a positive integer" % (option,))
|
||||
"a non negative integer" % (option,))
|
||||
return val
|
||||
|
||||
|
||||
@ -138,6 +148,14 @@ def validate_cert_reqs(option, value):
|
||||
% (option,))
|
||||
|
||||
|
||||
def validate_non_negative_integer_or_none(option, value):
|
||||
"""Validate that 'value' is a positive integer or 0 or None.
|
||||
"""
|
||||
if value is None:
|
||||
return value
|
||||
return validate_non_negative_integer(option, value)
|
||||
|
||||
|
||||
def validate_positive_integer_or_none(option, value):
|
||||
"""Validate that 'value' is a positive integer or None.
|
||||
"""
|
||||
@ -316,7 +334,7 @@ VALIDATORS = {
|
||||
'connecttimeoutms': validate_timeout_or_none,
|
||||
'sockettimeoutms': validate_timeout_or_none,
|
||||
'waitqueuetimeoutms': validate_timeout_or_none,
|
||||
'waitqueuemultiple': validate_positive_integer_or_none,
|
||||
'waitqueuemultiple': validate_non_negative_integer_or_none,
|
||||
'ssl': validate_boolean,
|
||||
'ssl_keyfile': validate_readable,
|
||||
'ssl_certfile': validate_readable,
|
||||
|
||||
@ -130,7 +130,7 @@ class MongoClient(common.BaseObject):
|
||||
- `max_pool_size` (optional): The maximum number of connections
|
||||
that the pool will open simultaneously. If this is set, operations
|
||||
will block if there are `max_pool_size` outstanding connections
|
||||
from the pool. Defaults to 100.
|
||||
from the pool. Defaults to 100. Cannot be 0.
|
||||
- `document_class` (optional): default class to use for
|
||||
documents returned from queries on this client
|
||||
- `tz_aware` (optional): if ``True``,
|
||||
@ -316,8 +316,8 @@ class MongoClient(common.BaseObject):
|
||||
|
||||
self.__max_pool_size = options.get(
|
||||
'maxpoolsize',
|
||||
common.validate_positive_integer_or_none('max_pool_size',
|
||||
max_pool_size))
|
||||
common.validate_positive_integer_or_none(
|
||||
'max_pool_size', max_pool_size))
|
||||
|
||||
self.__cursor_manager = CursorManager(self)
|
||||
|
||||
|
||||
@ -471,7 +471,7 @@ class MongoReplicaSetClient(common.BaseObject):
|
||||
- `max_pool_size` (optional): The maximum number of connections
|
||||
each pool will open simultaneously. If this is set, operations
|
||||
will block if there are `max_pool_size` outstanding connections
|
||||
from the pool. Defaults to 100.
|
||||
from the pool. Defaults to 100. Cannot be 0.
|
||||
- `document_class` (optional): default class to use for
|
||||
documents returned from queries on this client
|
||||
- `tz_aware` (optional): if ``True``,
|
||||
@ -635,8 +635,8 @@ class MongoReplicaSetClient(common.BaseObject):
|
||||
|
||||
self.__max_pool_size = self.__opts.get(
|
||||
'maxpoolsize',
|
||||
common.validate_positive_integer_or_none('max_pool_size',
|
||||
max_pool_size))
|
||||
common.validate_positive_integer_or_none(
|
||||
'max_pool_size', max_pool_size))
|
||||
|
||||
common.validate_boolean('tz_aware', tz_aware)
|
||||
uuid_representation = options.pop('uuidrepresentation', PYTHON_LEGACY)
|
||||
|
||||
@ -106,6 +106,9 @@ class TestClient(unittest.TestCase, TestRequestMixin):
|
||||
|
||||
self.assertRaises(ConfigurationError, MongoClient, [])
|
||||
|
||||
def test_max_pool_size_zero(self):
|
||||
self.assertRaises(ConfigurationError, MongoClient, maxPoolSize=0)
|
||||
|
||||
def test_constants(self):
|
||||
MongoClient.HOST = host
|
||||
MongoClient.PORT = port
|
||||
|
||||
@ -165,6 +165,10 @@ class TestReplicaSetClient(TestReplicaSetClientBase, TestRequestMixin):
|
||||
self.assertEqual(None, client._MongoReplicaSetClient__ssl_certfile)
|
||||
self.assertEqual(None, client._MongoReplicaSetClient__ssl_ca_certs)
|
||||
|
||||
def test_repl_max_pool_size_zero(self):
|
||||
self.assertRaises(ConfigurationError, MongoReplicaSetClient,
|
||||
maxPoolSize=0)
|
||||
|
||||
def test_init_disconnected(self):
|
||||
c = self._get_client(_connect=False)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user