Skip to content

PYTHON-2543 Do not mark a server unknown from a "writeErrors" response #570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pymongo/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
NotMasterError,
OperationFailure,
PyMongoError,
ServerSelectionTimeoutError)
ServerSelectionTimeoutError,
WriteError)
from pymongo.monitor import SrvMonitor
from pymongo.pool import PoolOptions
from pymongo.server import Server
Expand Down Expand Up @@ -578,6 +579,9 @@ def _handle_error(self, address, err_ctx):
# operation fails because of any network error besides a socket
# timeout...."
return
elif issubclass(exc_type, WriteError):
# Ignore writeErrors.
return
elif issubclass(exc_type, NotMasterError):
# As per the SDAM spec if:
# - the server sees a "not master" error, and
Expand Down
96 changes: 96 additions & 0 deletions test/discovery_and_monitoring/errors/write_errors_ignored.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"description": "writeErrors field is ignored",
"uri": "mongodb://a/?replicaSet=rs",
"phases": [
{
"description": "Primary A is discovered",
"responses": [
[
"a:27017",
{
"ok": 1,
"ismaster": true,
"hosts": [
"a:27017"
],
"setName": "rs",
"minWireVersion": 0,
"maxWireVersion": 9,
"topologyVersion": {
"processId": {
"$oid": "000000000000000000000001"
},
"counter": {
"$numberLong": "1"
}
}
}
]
],
"outcome": {
"servers": {
"a:27017": {
"type": "RSPrimary",
"setName": "rs",
"topologyVersion": {
"processId": {
"$oid": "000000000000000000000001"
},
"counter": {
"$numberLong": "1"
}
},
"pool": {
"generation": 0
}
}
},
"topologyType": "ReplicaSetWithPrimary",
"logicalSessionTimeoutMinutes": null,
"setName": "rs"
}
},
{
"description": "Ignore command error with writeErrors field",
"applicationErrors": [
{
"address": "a:27017",
"when": "afterHandshakeCompletes",
"maxWireVersion": 9,
"type": "command",
"response": {
"ok": 1,
"writeErrors": [
{
"errmsg": "NotMasterNoSlaveOk",
"code": 13435
}
]
}
}
],
"outcome": {
"servers": {
"a:27017": {
"type": "RSPrimary",
"setName": "rs",
"topologyVersion": {
"processId": {
"$oid": "000000000000000000000001"
},
"counter": {
"$numberLong": "1"
}
},
"pool": {
"generation": 0
}
}
},
"topologyType": "ReplicaSetWithPrimary",
"logicalSessionTimeoutMinutes": null,
"setName": "rs"
}
}
]
}
4 changes: 3 additions & 1 deletion test/test_discovery_and_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
NetworkTimeout,
NotMasterError,
OperationFailure)
from pymongo.helpers import _check_command_response
from pymongo.helpers import (_check_command_response,
_check_write_command_response)
from pymongo.ismaster import IsMaster
from pymongo.server_description import ServerDescription, SERVER_TYPE
from pymongo.settings import TopologySettings
Expand Down Expand Up @@ -94,6 +95,7 @@ def got_app_error(topology, app_error):
try:
if error_type == 'command':
_check_command_response(app_error['response'], max_wire_version)
_check_write_command_response(app_error['response'])
elif error_type == 'network':
raise AutoReconnect('mock non-timeout network error')
elif error_type == 'timeout':
Expand Down