PYTHON-2236 Reset the server pool only after marking the server Unknown

This commit is contained in:
Shane Harvey 2020-05-08 16:39:05 -07:00
parent fbafa9c847
commit 9a9f42bb99
3 changed files with 14 additions and 10 deletions

View File

@ -142,10 +142,12 @@ class Monitor(MonitorBase):
if self._publish:
self._listeners.publish_server_heartbeat_failed(
address, error_time, error)
self._topology.reset_pool(address)
default = ServerDescription(address, error=error)
# Reset the server pool only after marking the server Unknown.
self._topology.on_change(default)
self._topology.reset_pool(address)
self._avg_round_trip_time.reset()
if not retry:
self._avg_round_trip_time.reset()
# Server type defaults to Unknown.
return default

View File

@ -1767,7 +1767,7 @@ class TestMongoClientFailover(MockClientTest):
host='b:2', # Pass a secondary.
replicaSet='rs',
retryReads=False,
serverSelectionTimeoutMS=100,
serverSelectionTimeoutMS=1000,
)
self.addCleanup(c.close)
@ -1782,9 +1782,6 @@ class TestMongoClientFailover(MockClientTest):
# ServerSelectionTimeoutError or AutoReconnect (from
# MockPool.get_socket).
self.assertRaises(AutoReconnect, c.db.collection.find_one)
# The second attempt always raises ServerSelectionTimeoutError.
self.assertRaises(ServerSelectionTimeoutError,
c.db.collection.find_one)
# But it can reconnect.
c.revive_host('a:1')
@ -1804,7 +1801,7 @@ class TestMongoClientFailover(MockClientTest):
replicaSet='rs',
connect=False,
retryReads=False,
serverSelectionTimeoutMS=100)
serverSelectionTimeoutMS=1000)
self.addCleanup(c.close)
# Set host-specific information so we can test whether it is reset.

View File

@ -730,7 +730,8 @@ class TestTopologyErrors(TopologyTest):
if ismaster_count[0] in (1, 3):
return IsMaster({'ok': 1, 'maxWireVersion': 6}), 0
else:
raise AutoReconnect('mock monitor error')
raise AutoReconnect(
'mock monitor error #%s' % (ismaster_count[0],))
t = create_mock_topology(monitor_class=TestMonitor)
server = wait_for_master(t)
@ -738,10 +739,14 @@ class TestTopologyErrors(TopologyTest):
self.assertEqual(SERVER_TYPE.Standalone,
server.description.server_type)
# Second ismaster call, then immediately the third.
# Second ismaster call.
t.request_check_all()
self.assertEqual(3, ismaster_count[0])
# The third ismaster call (the immediate retry) happens sometime soon
# after the failed check triggered by request_check_all. Wait until
# the server becomes known again.
t.select_server(writable_server_selector, 0.250)
self.assertEqual(SERVER_TYPE.Standalone, get_type(t, 'a'))
self.assertEqual(3, ismaster_count[0])
def test_internal_monitor_error(self):
exception = AssertionError('internal error')