Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 88e5152

Browse files
lthHerman Lee
authored andcommitted
Add client error codes to distinguish between network timeout and loss
Summary: Previously, mysql clients returned CR_SERVER_LOST on any network exception, including timeout. This adds two new client error codes `CR_NET_READ_INTERRUPTED` and `CR_NET_WRITE_INTERRUPTED` which is returned on network timeout. `CR_SERVER_LOST` is still returned for everything else. Reference patches: e3052e1 e5b99cd Differential Revision: D6325225
1 parent 6436839 commit 88e5152

12 files changed

Lines changed: 333 additions & 21 deletions

File tree

‎include/errmsg.h‎

Lines changed: 141 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,152 @@ extern const char *client_errors[]; /* Error messages */
132132
#define CR_MANDATORY_TRACKER_NOT_FOUND 2071
133133
#define CR_INVALID_FACTOR_NO 2072
134134
#define CR_CANT_GET_SESSION_DATA 2073
135-
#define CR_ERROR_LAST /*Copy last error nr:*/ 2073
135+
#define CR_PLACEHOLDER_2074 2074
136+
#define CR_PLACEHOLDER_2075 2075
137+
#define CR_PLACEHOLDER_2076 2076
138+
#define CR_PLACEHOLDER_2077 2077
139+
#define CR_PLACEHOLDER_2078 2078
140+
#define CR_PLACEHOLDER_2079 2079
141+
#define CR_PLACEHOLDER_2080 2080
142+
#define CR_PLACEHOLDER_2081 2081
143+
#define CR_PLACEHOLDER_2082 2082
144+
#define CR_PLACEHOLDER_2083 2083
145+
#define CR_PLACEHOLDER_2084 2084
146+
#define CR_PLACEHOLDER_2085 2085
147+
#define CR_PLACEHOLDER_2086 2086
148+
#define CR_PLACEHOLDER_2087 2087
149+
#define CR_PLACEHOLDER_2088 2088
150+
#define CR_PLACEHOLDER_2089 2089
151+
#define CR_PLACEHOLDER_2090 2090
152+
#define CR_PLACEHOLDER_2091 2091
153+
#define CR_PLACEHOLDER_2092 2092
154+
#define CR_PLACEHOLDER_2093 2093
155+
#define CR_PLACEHOLDER_2094 2094
156+
#define CR_PLACEHOLDER_2095 2095
157+
#define CR_PLACEHOLDER_2096 2096
158+
#define CR_PLACEHOLDER_2097 2097
159+
#define CR_PLACEHOLDER_2098 2098
160+
#define CR_PLACEHOLDER_2099 2099
161+
#define CR_PLACEHOLDER_2100 2100
162+
#define CR_PLACEHOLDER_2101 2101
163+
#define CR_PLACEHOLDER_2102 2102
164+
#define CR_PLACEHOLDER_2103 2103
165+
#define CR_PLACEHOLDER_2104 2104
166+
#define CR_PLACEHOLDER_2105 2105
167+
#define CR_PLACEHOLDER_2106 2106
168+
#define CR_PLACEHOLDER_2107 2107
169+
#define CR_PLACEHOLDER_2108 2108
170+
#define CR_PLACEHOLDER_2109 2109
171+
#define CR_PLACEHOLDER_2110 2110
172+
#define CR_PLACEHOLDER_2111 2111
173+
#define CR_PLACEHOLDER_2112 2112
174+
#define CR_PLACEHOLDER_2113 2113
175+
#define CR_PLACEHOLDER_2114 2114
176+
#define CR_PLACEHOLDER_2115 2115
177+
#define CR_PLACEHOLDER_2116 2116
178+
#define CR_PLACEHOLDER_2117 2117
179+
#define CR_PLACEHOLDER_2118 2118
180+
#define CR_PLACEHOLDER_2119 2119
181+
#define CR_PLACEHOLDER_2120 2120
182+
#define CR_PLACEHOLDER_2121 2121
183+
#define CR_PLACEHOLDER_2122 2122
184+
#define CR_PLACEHOLDER_2123 2123
185+
#define CR_PLACEHOLDER_2124 2124
186+
#define CR_PLACEHOLDER_2125 2125
187+
#define CR_PLACEHOLDER_2126 2126
188+
#define CR_PLACEHOLDER_2127 2127
189+
#define CR_PLACEHOLDER_2128 2128
190+
#define CR_PLACEHOLDER_2129 2129
191+
#define CR_PLACEHOLDER_2130 2130
192+
#define CR_PLACEHOLDER_2131 2131
193+
#define CR_PLACEHOLDER_2132 2132
194+
#define CR_PLACEHOLDER_2133 2133
195+
#define CR_PLACEHOLDER_2134 2134
196+
#define CR_PLACEHOLDER_2135 2135
197+
#define CR_PLACEHOLDER_2136 2136
198+
#define CR_PLACEHOLDER_2137 2137
199+
#define CR_PLACEHOLDER_2138 2138
200+
#define CR_PLACEHOLDER_2139 2139
201+
#define CR_PLACEHOLDER_2140 2140
202+
#define CR_PLACEHOLDER_2141 2141
203+
#define CR_PLACEHOLDER_2142 2142
204+
#define CR_PLACEHOLDER_2143 2143
205+
#define CR_PLACEHOLDER_2144 2144
206+
#define CR_PLACEHOLDER_2145 2145
207+
#define CR_PLACEHOLDER_2146 2146
208+
#define CR_PLACEHOLDER_2147 2147
209+
#define CR_PLACEHOLDER_2148 2148
210+
#define CR_PLACEHOLDER_2149 2149
211+
#define CR_PLACEHOLDER_2150 2150
212+
#define CR_PLACEHOLDER_2151 2151
213+
#define CR_PLACEHOLDER_2152 2152
214+
#define CR_PLACEHOLDER_2153 2153
215+
#define CR_PLACEHOLDER_2154 2154
216+
#define CR_PLACEHOLDER_2155 2155
217+
#define CR_PLACEHOLDER_2156 2156
218+
#define CR_PLACEHOLDER_2157 2157
219+
#define CR_PLACEHOLDER_2158 2158
220+
#define CR_PLACEHOLDER_2159 2159
221+
#define CR_PLACEHOLDER_2160 2160
222+
#define CR_PLACEHOLDER_2161 2161
223+
#define CR_PLACEHOLDER_2162 2162
224+
#define CR_PLACEHOLDER_2163 2163
225+
#define CR_PLACEHOLDER_2164 2164
226+
#define CR_PLACEHOLDER_2165 2165
227+
#define CR_PLACEHOLDER_2166 2166
228+
#define CR_PLACEHOLDER_2167 2167
229+
#define CR_PLACEHOLDER_2168 2168
230+
#define CR_PLACEHOLDER_2169 2169
231+
#define CR_PLACEHOLDER_2170 2170
232+
#define CR_PLACEHOLDER_2171 2171
233+
#define CR_PLACEHOLDER_2172 2172
234+
#define CR_PLACEHOLDER_2173 2173
235+
#define CR_PLACEHOLDER_2174 2174
236+
#define CR_PLACEHOLDER_2175 2175
237+
#define CR_PLACEHOLDER_2176 2176
238+
#define CR_PLACEHOLDER_2177 2177
239+
#define CR_PLACEHOLDER_2178 2178
240+
#define CR_PLACEHOLDER_2179 2179
241+
#define CR_PLACEHOLDER_2180 2180
242+
#define CR_PLACEHOLDER_2181 2181
243+
#define CR_PLACEHOLDER_2182 2182
244+
#define CR_PLACEHOLDER_2183 2183
245+
#define CR_PLACEHOLDER_2184 2184
246+
#define CR_PLACEHOLDER_2185 2185
247+
#define CR_PLACEHOLDER_2186 2186
248+
#define CR_PLACEHOLDER_2187 2187
249+
#define CR_PLACEHOLDER_2188 2188
250+
#define CR_PLACEHOLDER_2189 2189
251+
#define CR_PLACEHOLDER_2190 2190
252+
#define CR_PLACEHOLDER_2191 2191
253+
#define CR_PLACEHOLDER_2192 2192
254+
#define CR_PLACEHOLDER_2193 2193
255+
#define CR_PLACEHOLDER_2194 2194
256+
#define CR_PLACEHOLDER_2195 2195
257+
#define CR_PLACEHOLDER_2196 2196
258+
#define CR_PLACEHOLDER_2197 2197
259+
#define CR_PLACEHOLDER_2198 2198
260+
#define CR_PLACEHOLDER_2199 2199
261+
// Facebook client errors
262+
#define CR_NET_READ_INTERRUPTED 2200
263+
#define CR_NET_WRITE_INTERRUPTED 2201
264+
#define CR_ERROR_LAST /*Copy last error nr:*/ 2201
136265
/* Add error numbers before CR_ERROR_LAST and change it accordingly. */
137266

267+
#define CR_PLACEHOLDER_FIRST CR_PLACEHOLDER_2074
268+
#define CR_PLACEHOLDER_LAST CR_PLACEHOLDER_2199
269+
270+
static inline bool isPlaceHolder(int client_errno) {
271+
return client_errno >= CR_PLACEHOLDER_FIRST &&
272+
client_errno <= CR_PLACEHOLDER_LAST;
273+
}
274+
138275
/* Visual Studio requires '__inline' for C code */
139276
static inline const char *ER_CLIENT(int client_errno) {
140-
if (client_errno >= CR_ERROR_FIRST && client_errno <= CR_ERROR_LAST)
277+
if (client_errno >= CR_ERROR_FIRST && client_errno <= CR_ERROR_LAST &&
278+
!isPlaceHolder(client_errno)) {
141279
return client_errors[client_errno - CR_ERROR_FIRST];
280+
}
142281
return client_errors[CR_UNKNOWN_ERROR - CR_ERROR_FIRST];
143282
}
144283

‎include/mysql.h.pp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,15 @@
363363
void init_client_errs(void);
364364
void finish_client_errs(void);
365365
extern const char *client_errors[];
366+
static inline bool isPlaceHolder(int client_errno) {
367+
return client_errno >= 2074 &&
368+
client_errno <= 2199;
369+
}
366370
static inline const char *ER_CLIENT(int client_errno) {
367-
if (client_errno >= 2000 && client_errno <= 2073)
371+
if (client_errno >= 2000 && client_errno <= 2201 &&
372+
!isPlaceHolder(client_errno)) {
368373
return client_errors[client_errno - 2000];
374+
}
369375
return client_errors[2000 - 2000];
370376
}
371377
extern unsigned int mysql_port;

‎libmysql/errmsg.cc‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,134 @@ const char *client_errors[] = {
119119
"Invalid first argument for MYSQL_OPT_USER_PASSWORD option. Valid value "
120120
"should be between 1 and 3 inclusive.",
121121
"Can't get session data: %s",
122+
"Placeholder 2074",
123+
"Placeholder 2075",
124+
"Placeholder 2076",
125+
"Placeholder 2077",
126+
"Placeholder 2078",
127+
"Placeholder 2079",
128+
"Placeholder 2080",
129+
"Placeholder 2081",
130+
"Placeholder 2082",
131+
"Placeholder 2083",
132+
"Placeholder 2084",
133+
"Placeholder 2085",
134+
"Placeholder 2086",
135+
"Placeholder 2087",
136+
"Placeholder 2088",
137+
"Placeholder 2089",
138+
"Placeholder 2090",
139+
"Placeholder 2091",
140+
"Placeholder 2092",
141+
"Placeholder 2093",
142+
"Placeholder 2094",
143+
"Placeholder 2095",
144+
"Placeholder 2096",
145+
"Placeholder 2097",
146+
"Placeholder 2098",
147+
"Placeholder 2099",
148+
"Placeholder 2100",
149+
"Placeholder 2101",
150+
"Placeholder 2102",
151+
"Placeholder 2103",
152+
"Placeholder 2104",
153+
"Placeholder 2105",
154+
"Placeholder 2106",
155+
"Placeholder 2107",
156+
"Placeholder 2108",
157+
"Placeholder 2109",
158+
"Placeholder 2110",
159+
"Placeholder 2111",
160+
"Placeholder 2112",
161+
"Placeholder 2113",
162+
"Placeholder 2114",
163+
"Placeholder 2115",
164+
"Placeholder 2116",
165+
"Placeholder 2117",
166+
"Placeholder 2118",
167+
"Placeholder 2119",
168+
"Placeholder 2120",
169+
"Placeholder 2121",
170+
"Placeholder 2122",
171+
"Placeholder 2123",
172+
"Placeholder 2124",
173+
"Placeholder 2125",
174+
"Placeholder 2126",
175+
"Placeholder 2127",
176+
"Placeholder 2128",
177+
"Placeholder 2129",
178+
"Placeholder 2130",
179+
"Placeholder 2131",
180+
"Placeholder 2132",
181+
"Placeholder 2133",
182+
"Placeholder 2134",
183+
"Placeholder 2135",
184+
"Placeholder 2136",
185+
"Placeholder 2137",
186+
"Placeholder 2138",
187+
"Placeholder 2139",
188+
"Placeholder 2140",
189+
"Placeholder 2141",
190+
"Placeholder 2142",
191+
"Placeholder 2143",
192+
"Placeholder 2144",
193+
"Placeholder 2145",
194+
"Placeholder 2146",
195+
"Placeholder 2147",
196+
"Placeholder 2148",
197+
"Placeholder 2149",
198+
"Placeholder 2150",
199+
"Placeholder 2151",
200+
"Placeholder 2152",
201+
"Placeholder 2153",
202+
"Placeholder 2154",
203+
"Placeholder 2155",
204+
"Placeholder 2156",
205+
"Placeholder 2157",
206+
"Placeholder 2158",
207+
"Placeholder 2159",
208+
"Placeholder 2160",
209+
"Placeholder 2161",
210+
"Placeholder 2162",
211+
"Placeholder 2163",
212+
"Placeholder 2164",
213+
"Placeholder 2165",
214+
"Placeholder 2166",
215+
"Placeholder 2167",
216+
"Placeholder 2168",
217+
"Placeholder 2169",
218+
"Placeholder 2170",
219+
"Placeholder 2171",
220+
"Placeholder 2172",
221+
"Placeholder 2173",
222+
"Placeholder 2174",
223+
"Placeholder 2175",
224+
"Placeholder 2176",
225+
"Placeholder 2177",
226+
"Placeholder 2178",
227+
"Placeholder 2179",
228+
"Placeholder 2180",
229+
"Placeholder 2181",
230+
"Placeholder 2182",
231+
"Placeholder 2183",
232+
"Placeholder 2184",
233+
"Placeholder 2185",
234+
"Placeholder 2186",
235+
"Placeholder 2187",
236+
"Placeholder 2188",
237+
"Placeholder 2189",
238+
"Placeholder 2190",
239+
"Placeholder 2191",
240+
"Placeholder 2192",
241+
"Placeholder 2193",
242+
"Placeholder 2194",
243+
"Placeholder 2195",
244+
"Placeholder 2196",
245+
"Placeholder 2197",
246+
"Placeholder 2198",
247+
"Placeholder 2199",
248+
"Read timeout is reached",
249+
"Write timeout is reached",
122250
""};
123251

124252
static const char *get_client_errmsg(int nr) {

‎libmysql/libmysql.cc‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,8 +1797,16 @@ static bool execute(MYSQL_STMT *stmt, char *packet, ulong length,
17971797
/*
17981798
Don't set stmt error if stmt->mysql is NULL, as the error in this case
17991799
has already been set by mysql_prune_stmt_list().
1800+
1801+
Special case for CR_NET_(READ|WRITE)_INTERRUPTED because they were
1802+
added to disambiguate them from CR_SERVER_LOST. mysql_prune_stmt_list
1803+
sets CR_SERVER_LOST for the whole stmt list, but we want the
1804+
statement causing timeout to get the correct error and the rest to get
1805+
CR_SERVER_LOST.
18001806
*/
1801-
if (stmt->mysql) set_stmt_errmsg(stmt, net);
1807+
if (stmt->mysql || net->last_errno == CR_NET_READ_INTERRUPTED ||
1808+
net->last_errno == CR_NET_WRITE_INTERRUPTED)
1809+
set_stmt_errmsg(stmt, net);
18021810
return true;
18031811
} else if (mysql->status == MYSQL_STATUS_GET_RESULT)
18041812
stmt->mysql->status = MYSQL_STATUS_STATEMENT_GET_RESULT;
@@ -1974,8 +1982,16 @@ static int stmt_read_row_from_cursor(MYSQL_STMT *stmt, unsigned char **row) {
19741982
/*
19751983
Don't set stmt error if stmt->mysql is NULL, as the error in this case
19761984
has already been set by mysql_prune_stmt_list().
1985+
1986+
Special case for CR_NET_(READ|WRITE)_INTERRUPTED because they were
1987+
added to disambiguate them from CR_SERVER_LOST. mysql_prune_stmt_list
1988+
sets CR_SERVER_LOST for the whole stmt list, but we want the
1989+
statement causing timeout to get the correct error and the rest to get
1990+
CR_SERVER_LOST.
19771991
*/
1978-
if (stmt->mysql) set_stmt_errmsg(stmt, net);
1992+
if (stmt->mysql || net->last_errno == CR_NET_READ_INTERRUPTED ||
1993+
net->last_errno == CR_NET_WRITE_INTERRUPTED)
1994+
set_stmt_errmsg(stmt, net);
19791995
return 1;
19801996
}
19811997
if ((*mysql->methods->read_rows_from_cursor)(stmt)) return 1;
@@ -2577,8 +2593,16 @@ bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number,
25772593
/*
25782594
Don't set stmt error if stmt->mysql is NULL, as the error in this case
25792595
has already been set by mysql_prune_stmt_list().
2596+
2597+
Special case for CR_NET_(READ|WRITE)_INTERRUPTED because they were
2598+
added to disambiguate them from CR_SERVER_LOST. mysql_prune_stmt_list
2599+
sets CR_SERVER_LOST for the whole stmt list, but we want the
2600+
statement causing timeout to get the correct error and the rest to get
2601+
CR_SERVER_LOST.
25802602
*/
2581-
if (stmt->mysql) set_stmt_errmsg(stmt, &mysql->net);
2603+
if (stmt->mysql || mysql->net.last_errno == CR_NET_READ_INTERRUPTED ||
2604+
mysql->net.last_errno == CR_NET_WRITE_INTERRUPTED)
2605+
set_stmt_errmsg(stmt, &mysql->net);
25822606
return true;
25832607
}
25842608
}
@@ -3957,8 +3981,16 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) {
39573981
/*
39583982
Don't set stmt error if stmt->mysql is NULL, as the error in this case
39593983
has already been set by mysql_prune_stmt_list().
3984+
3985+
Special case for CR_NET_(READ|WRITE)_INTERRUPTED because they were
3986+
added to disambiguate them from CR_SERVER_LOST. mysql_prune_stmt_list
3987+
sets CR_SERVER_LOST for the whole stmt list, but we want the
3988+
statement causing timeout to get the correct error and the rest to get
3989+
CR_SERVER_LOST.
39603990
*/
3961-
if (stmt->mysql) set_stmt_errmsg(stmt, net);
3991+
if (stmt->mysql || net->last_errno == CR_NET_READ_INTERRUPTED ||
3992+
net->last_errno == CR_NET_WRITE_INTERRUPTED)
3993+
set_stmt_errmsg(stmt, net);
39623994
return 1;
39633995
}
39643996
} else if (mysql->status != MYSQL_STATUS_STATEMENT_GET_RESULT) {

‎mysql-test/include/wait_time_until_connected_again.inc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ while ($mysql_errno)
1212
# Strangely enough, the server might return "Too many connections"
1313
# while being shutdown, thus 1040 is an "allowed" error
1414
# See BUG#36228
15-
--error 0,1040,1053,2002,2003,2006,2013,2016,2017
15+
--error 0,1040,1053,2002,2003,2006,2013,2016,2017,2071
1616
show status;
1717

1818
dec $counter;

‎mysql-test/include/wait_until_connected_again.inc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ while ($mysql_errno)
4040
# Strangely enough, the server might return "Too many connections"
4141
# while being shutdown, thus 1040 is an "allowed" error
4242
# See BUG#36228
43-
--error 0,1040,1053,2002,2003,2006,2013,1045,ER_SECURE_TRANSPORT_REQUIRED,2016,2017,ER_CLIENT_INTERACTION_TIMEOUT
43+
--error 0,1040,1053,2002,2003,2006,2013,1045,ER_SECURE_TRANSPORT_REQUIRED,2016,2017,2200,ER_CLIENT_INTERACTION_TIMEOUT
4444
show session status;
4545
if ($mysql_errno == 1045){
4646
--let mysql_errno=0

0 commit comments

Comments
 (0)