PYTHON-4993 - Reevaluate handling of asyncio.CancelledError (#2132)
This commit is contained in:
parent
42d7ec2749
commit
8496d58faa
@ -127,8 +127,6 @@ def _wrap_encryption_errors() -> Iterator[None]:
|
||||
# BSON encoding/decoding errors are unrelated to encryption so
|
||||
# we should propagate them unchanged.
|
||||
raise
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
raise EncryptionError(exc) from exc
|
||||
|
||||
@ -766,8 +764,6 @@ class AsyncClientEncryption(Generic[_DocumentType]):
|
||||
await database.create_collection(name=name, **kwargs),
|
||||
encrypted_fields,
|
||||
)
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
raise EncryptedCollectionError(exc, encrypted_fields) from exc
|
||||
|
||||
|
||||
@ -2043,8 +2043,6 @@ class AsyncMongoClient(common.BaseObject, Generic[_DocumentType]):
|
||||
for address, cursor_id, conn_mgr in pinned_cursors:
|
||||
try:
|
||||
await self._cleanup_cursor_lock(cursor_id, address, conn_mgr, None, False)
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
if isinstance(exc, InvalidOperation) and self._topology._closed:
|
||||
# Raise the exception when client is closed so that it
|
||||
@ -2059,8 +2057,6 @@ class AsyncMongoClient(common.BaseObject, Generic[_DocumentType]):
|
||||
for address, cursor_ids in address_to_cursor_ids.items():
|
||||
try:
|
||||
await self._kill_cursors(cursor_ids, address, topology, session=None)
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
if isinstance(exc, InvalidOperation) and self._topology._closed:
|
||||
raise
|
||||
@ -2075,8 +2071,6 @@ class AsyncMongoClient(common.BaseObject, Generic[_DocumentType]):
|
||||
try:
|
||||
await self._process_kill_cursors()
|
||||
await self._topology.update_pool()
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
if isinstance(exc, InvalidOperation) and self._topology._closed:
|
||||
return
|
||||
|
||||
@ -262,8 +262,6 @@ class Monitor(MonitorBase):
|
||||
details = cast(Mapping[str, Any], exc.details)
|
||||
await self._topology.receive_cluster_time(details.get("$clusterTime"))
|
||||
raise
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except ReferenceError:
|
||||
raise
|
||||
except Exception as error:
|
||||
@ -429,8 +427,6 @@ class SrvMonitor(MonitorBase):
|
||||
if len(seedlist) == 0:
|
||||
# As per the spec: this should be treated as a failure.
|
||||
raise Exception
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception:
|
||||
# As per the spec, upon encountering an error:
|
||||
# - An error must not be raised
|
||||
@ -494,8 +490,6 @@ class _RttMonitor(MonitorBase):
|
||||
except ReferenceError:
|
||||
# Topology was garbage-collected.
|
||||
await self.close()
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception:
|
||||
await self._pool.reset()
|
||||
|
||||
|
||||
@ -706,8 +706,6 @@ class AsyncConnection:
|
||||
# shutdown.
|
||||
try:
|
||||
self.conn.close()
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception: # noqa: S110
|
||||
pass
|
||||
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
"""Support for explicit client-side field level encryption."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
import enum
|
||||
import socket
|
||||
@ -127,8 +126,6 @@ def _wrap_encryption_errors() -> Iterator[None]:
|
||||
# BSON encoding/decoding errors are unrelated to encryption so
|
||||
# we should propagate them unchanged.
|
||||
raise
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
raise EncryptionError(exc) from exc
|
||||
|
||||
@ -760,8 +757,6 @@ class ClientEncryption(Generic[_DocumentType]):
|
||||
database.create_collection(name=name, **kwargs),
|
||||
encrypted_fields,
|
||||
)
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
raise EncryptedCollectionError(exc, encrypted_fields) from exc
|
||||
|
||||
|
||||
@ -2037,8 +2037,6 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]):
|
||||
for address, cursor_id, conn_mgr in pinned_cursors:
|
||||
try:
|
||||
self._cleanup_cursor_lock(cursor_id, address, conn_mgr, None, False)
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
if isinstance(exc, InvalidOperation) and self._topology._closed:
|
||||
# Raise the exception when client is closed so that it
|
||||
@ -2053,8 +2051,6 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]):
|
||||
for address, cursor_ids in address_to_cursor_ids.items():
|
||||
try:
|
||||
self._kill_cursors(cursor_ids, address, topology, session=None)
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
if isinstance(exc, InvalidOperation) and self._topology._closed:
|
||||
raise
|
||||
@ -2069,8 +2065,6 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]):
|
||||
try:
|
||||
self._process_kill_cursors()
|
||||
self._topology.update_pool()
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
if isinstance(exc, InvalidOperation) and self._topology._closed:
|
||||
return
|
||||
|
||||
@ -260,8 +260,6 @@ class Monitor(MonitorBase):
|
||||
details = cast(Mapping[str, Any], exc.details)
|
||||
self._topology.receive_cluster_time(details.get("$clusterTime"))
|
||||
raise
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except ReferenceError:
|
||||
raise
|
||||
except Exception as error:
|
||||
@ -427,8 +425,6 @@ class SrvMonitor(MonitorBase):
|
||||
if len(seedlist) == 0:
|
||||
# As per the spec: this should be treated as a failure.
|
||||
raise Exception
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception:
|
||||
# As per the spec, upon encountering an error:
|
||||
# - An error must not be raised
|
||||
@ -492,8 +488,6 @@ class _RttMonitor(MonitorBase):
|
||||
except ReferenceError:
|
||||
# Topology was garbage-collected.
|
||||
self.close()
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception:
|
||||
self._pool.reset()
|
||||
|
||||
|
||||
@ -704,8 +704,6 @@ class Connection:
|
||||
# shutdown.
|
||||
try:
|
||||
self.conn.close()
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
except Exception: # noqa: S110
|
||||
pass
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user