Skip to content

Commit 301dc6f

Browse files
committed
handle SystemOverloadedError on command errors
1 parent 65f7f0d commit 301dc6f

File tree

5 files changed

+156
-2
lines changed

5 files changed

+156
-2
lines changed

pymongo/asynchronous/topology.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,8 @@ async def _handle_error(self, address: _Address, err_ctx: _ErrorContext) -> None
868868
# as Unknown and request an immediate check of the server.
869869
# Otherwise, we clear the connection pool, mark the server as
870870
# Unknown and request an immediate check of the server.
871+
if error.has_error_label("SystemOverloadedError"):
872+
return
871873
if hasattr(error, "code"):
872874
err_code = error.code
873875
else:

pymongo/synchronous/topology.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,8 @@ def _handle_error(self, address: _Address, err_ctx: _ErrorContext) -> None:
866866
# as Unknown and request an immediate check of the server.
867867
# Otherwise, we clear the connection pool, mark the server as
868868
# Unknown and request an immediate check of the server.
869+
if error.has_error_label("SystemOverloadedError"):
870+
return
869871
if hasattr(error, "code"):
870872
err_code = error.code
871873
else:
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"description": "backpressure hello-command-error",
3+
"schemaVersion": "1.4",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "4.4.7",
7+
"serverless": "forbid",
8+
"topologies": [
9+
"single",
10+
"replicaset",
11+
"sharded"
12+
]
13+
}
14+
],
15+
"createEntities": [
16+
{
17+
"client": {
18+
"id": "setupClient",
19+
"useMultipleMongoses": false
20+
}
21+
}
22+
],
23+
"initialData": [
24+
{
25+
"collectionName": "backpressure hello-command-error",
26+
"databaseName": "sdam-tests",
27+
"documents": []
28+
}
29+
],
30+
"tests": [
31+
{
32+
"description": "hello command error with backpressure label does not clear the pool",
33+
"operations": [
34+
{
35+
"name": "createEntities",
36+
"object": "testRunner",
37+
"arguments": {
38+
"entities": [
39+
{
40+
"client": {
41+
"id": "client",
42+
"useMultipleMongoses": false,
43+
"observeEvents": [
44+
"serverHeartbeatSucceededEvent",
45+
"poolClearedEvent",
46+
"poolReadyEvent",
47+
"commandStartedEvent"
48+
],
49+
"uriOptions": {
50+
"retryWrites": false,
51+
"heartbeatFrequencyMS": 10000,
52+
"serverMonitoringMode": "poll",
53+
"directConnection": true,
54+
"appname": "backpressureCommandErrorHandshakeTest"
55+
}
56+
}
57+
},
58+
{
59+
"database": {
60+
"id": "database",
61+
"client": "client",
62+
"databaseName": "sdam-tests"
63+
}
64+
},
65+
{
66+
"collection": {
67+
"id": "collection",
68+
"database": "database",
69+
"collectionName": "backpressure hello-command-error"
70+
}
71+
}
72+
]
73+
}
74+
},
75+
{
76+
"name": "waitForEvent",
77+
"object": "testRunner",
78+
"arguments": {
79+
"client": "client",
80+
"event": {
81+
"serverHeartbeatSucceededEvent": {}
82+
},
83+
"count": 1
84+
}
85+
},
86+
{
87+
"name": "failPoint",
88+
"object": "testRunner",
89+
"arguments": {
90+
"client": "setupClient",
91+
"failPoint": {
92+
"configureFailPoint": "failCommand",
93+
"mode": "alwaysOn",
94+
"data": {
95+
"failCommands": [
96+
"hello",
97+
"isMaster"
98+
],
99+
"appName": "backpressureCommandErrorHandshakeTest",
100+
"closeConnection": false,
101+
"errorCode": 9001,
102+
"errorLabels": [
103+
"SystemOverloadedError"
104+
]
105+
}
106+
}
107+
}
108+
},
109+
{
110+
"name": "insertMany",
111+
"object": "collection",
112+
"arguments": {
113+
"documents": [
114+
{
115+
"_id": 1
116+
},
117+
{
118+
"_id": 2
119+
}
120+
]
121+
},
122+
"expectError": {
123+
"isError": true
124+
}
125+
}
126+
],
127+
"expectEvents": [
128+
{
129+
"client": "client",
130+
"eventType": "cmap",
131+
"events": [
132+
{
133+
"poolReadyEvent": {}
134+
}
135+
]
136+
},
137+
{
138+
"client": "client",
139+
"eventType": "sdam",
140+
"ignoreExtraEvents": false,
141+
"events": [
142+
{
143+
"serverHeartbeatSucceededEvent": {}
144+
}
145+
]
146+
}
147+
]
148+
}
149+
]
150+
}

test/discovery_and_monitoring/unified/backpressure-network-error-fail.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
],
3737
"tests": [
3838
{
39-
"description": "Apply backpressure on network connection errors during connection establishment",
39+
"description": "apply backpressure on network connection errors during connection establishment",
4040
"operations": [
4141
{
4242
"name": "createEntities",

test/discovery_and_monitoring/unified/backpressure-network-timeout-fail.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
],
3737
"tests": [
3838
{
39-
"description": "Apply backpressure on network timeout error during connection establishment",
39+
"description": "apply backpressure on network timeout error during connection establishment",
4040
"operations": [
4141
{
4242
"name": "createEntities",

0 commit comments

Comments
 (0)