PYTHON-6226ClosedFixed

AsyncMongoClient stays stuck in ReplicaSetNoPrimary after a monitor task cancels itself

h3. Description We hit this in production when a replica set node ran out of memory (OOM) and restarted. The client kept failing server selection and only recovered after the client process was restarted. We verified that the bug described below was the cause. If a server's own {{hello}} response removes it from the topology, {{_update_servers()}} closes that server from inside its own monitor task. {{AsyncPeriodicExecutor.close()}} then cancels the current task: {{CancelledError}}

Affected Versions
Versions known to exhibit this issue
4.19.0
Fixed Versions
Versions that include the fix
4.20.0
Components
Server components related to this issue

No components specified.

Labels
Tags and classification

No labels assigned.