6767from pymongo .asynchronous .client_bulk import _AsyncClientBulk
6868from pymongo .asynchronous .client_session import _EmptyServerSession
6969from pymongo .asynchronous .command_cursor import AsyncCommandCursor
70+ from pymongo .asynchronous .helpers import _MAX_RETRIES , _backoff , _retry_overload
7071from pymongo .asynchronous .settings import TopologySettings
7172from pymongo .asynchronous .topology import Topology , _ErrorContext
7273from pymongo .client_options import ClientOptions
@@ -2398,6 +2399,7 @@ async def list_database_names(
23982399 return [doc ["name" ] async for doc in res ]
23992400
24002401 @_csot .apply
2402+ @_retry_overload
24012403 async def drop_database (
24022404 self ,
24032405 name_or_database : Union [str , database .AsyncDatabase [_DocumentTypeArg ]],
@@ -2783,14 +2785,19 @@ async def run(self) -> T:
27832785 # most likely be a waste of time.
27842786 raise
27852787 except PyMongoError as exc :
2788+ overload = False
27862789 # Execute specialized catch on read
27872790 if self ._is_read :
27882791 if isinstance (exc , (ConnectionFailure , OperationFailure )):
27892792 # ConnectionFailures do not supply a code property
27902793 exc_code = getattr (exc , "code" , None )
2791- if self ._is_not_eligible_for_retry () or (
2792- isinstance (exc , OperationFailure )
2793- and exc_code not in helpers_shared ._RETRYABLE_ERROR_CODES
2794+ overload = exc .has_error_label ("Retryable" )
2795+ if not overload and (
2796+ self ._is_not_eligible_for_retry ()
2797+ or (
2798+ isinstance (exc , OperationFailure )
2799+ and exc_code not in helpers_shared ._RETRYABLE_ERROR_CODES
2800+ )
27942801 ):
27952802 raise
27962803 self ._retrying = True
@@ -2807,12 +2814,18 @@ async def run(self) -> T:
28072814 retryable_write_error_exc = isinstance (
28082815 exc .error , PyMongoError
28092816 ) and exc .error .has_error_label ("RetryableWriteError" )
2817+ overload = isinstance (
2818+ exc .error , PyMongoError
2819+ ) and exc .error .has_error_label ("Retryable" )
28102820 else :
28112821 retryable_write_error_exc = exc .has_error_label ("RetryableWriteError" )
2812- if retryable_write_error_exc :
2822+ overload = exc .has_error_label ("Retryable" )
2823+ if retryable_write_error_exc or overload :
28132824 assert self ._session
28142825 await self ._session ._unpin ()
2815- if not retryable_write_error_exc or self ._is_not_eligible_for_retry ():
2826+ if not overload and (
2827+ not retryable_write_error_exc or not self ._is_not_eligible_for_retry ()
2828+ ):
28162829 if exc .has_error_label ("NoWritesPerformed" ) and self ._last_error :
28172830 raise self ._last_error from exc
28182831 else :
@@ -2830,6 +2843,14 @@ async def run(self) -> T:
28302843 if self ._client .topology_description .topology_type == TOPOLOGY_TYPE .Sharded :
28312844 self ._deprioritized_servers .append (self ._server )
28322845
2846+ if overload :
2847+ if self ._attempt_number > _MAX_RETRIES :
2848+ if exc .has_error_label ("NoWritesPerformed" ) and self ._last_error :
2849+ raise self ._last_error from exc
2850+ else :
2851+ raise
2852+ await _backoff (self ._attempt_number )
2853+
28332854 def _is_not_eligible_for_retry (self ) -> bool :
28342855 """Checks if the exchange is not eligible for retry"""
28352856 return not self ._retryable or (self ._is_retrying () and not self ._multiple_retries )
0 commit comments