Skip to content

Commit

Permalink
PYTHON-4980 Ignore network error on killAllSessions (#2011)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneHarvey authored Nov 19, 2024
1 parent ddf783b commit b5f0104
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion test/asynchronous/unified_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
from pymongo.asynchronous.helpers import anext
from pymongo.encryption_options import _HAVE_PYMONGOCRYPT
from pymongo.errors import (
AutoReconnect,
BulkWriteError,
ClientBulkWriteException,
ConfigurationError,
Expand Down Expand Up @@ -755,9 +756,10 @@ async def kill_all_sessions(self):
for client in clients:
try:
await client.admin.command("killAllSessions", [])
except OperationFailure:
except (OperationFailure, AutoReconnect):
# "operation was interrupted" by killing the command's
# own session.
# On 8.0+ killAllSessions sometimes returns a network error.
pass

async def _databaseOperation_listCollections(self, target, *args, **kwargs):
Expand Down
5 changes: 3 additions & 2 deletions test/asynchronous/utils_spec_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from pymongo.asynchronous import client_session
from pymongo.asynchronous.command_cursor import AsyncCommandCursor
from pymongo.asynchronous.cursor import AsyncCursor
from pymongo.errors import BulkWriteError, OperationFailure, PyMongoError
from pymongo.errors import AutoReconnect, BulkWriteError, OperationFailure, PyMongoError
from pymongo.read_concern import ReadConcern
from pymongo.read_preferences import ReadPreference
from pymongo.results import BulkWriteResult, _WriteResult
Expand Down Expand Up @@ -343,9 +343,10 @@ async def kill_all_sessions(self):
for client in clients:
try:
await client.admin.command("killAllSessions", [])
except OperationFailure:
except (OperationFailure, AutoReconnect):
# "operation was interrupted" by killing the command's
# own session.
# On 8.0+ killAllSessions sometimes returns a network error.
pass

def check_command_result(self, expected_result, result):
Expand Down
4 changes: 3 additions & 1 deletion test/unified_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
from pymongo import ASCENDING, CursorType, MongoClient, _csot
from pymongo.encryption_options import _HAVE_PYMONGOCRYPT
from pymongo.errors import (
AutoReconnect,
BulkWriteError,
ClientBulkWriteException,
ConfigurationError,
Expand Down Expand Up @@ -751,9 +752,10 @@ def kill_all_sessions(self):
for client in clients:
try:
client.admin.command("killAllSessions", [])
except OperationFailure:
except (OperationFailure, AutoReconnect):
# "operation was interrupted" by killing the command's
# own session.
# On 8.0+ killAllSessions sometimes returns a network error.
pass

def _databaseOperation_listCollections(self, target, *args, **kwargs):
Expand Down
5 changes: 3 additions & 2 deletions test/utils_spec_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from bson.son import SON
from gridfs import GridFSBucket
from gridfs.synchronous.grid_file import GridFSBucket
from pymongo.errors import BulkWriteError, OperationFailure, PyMongoError
from pymongo.errors import AutoReconnect, BulkWriteError, OperationFailure, PyMongoError
from pymongo.read_concern import ReadConcern
from pymongo.read_preferences import ReadPreference
from pymongo.results import BulkWriteResult, _WriteResult
Expand Down Expand Up @@ -343,9 +343,10 @@ def kill_all_sessions(self):
for client in clients:
try:
client.admin.command("killAllSessions", [])
except OperationFailure:
except (OperationFailure, AutoReconnect):
# "operation was interrupted" by killing the command's
# own session.
# On 8.0+ killAllSessions sometimes returns a network error.
pass

def check_command_result(self, expected_result, result):
Expand Down

0 comments on commit b5f0104

Please sign in to comment.