@@ -115,13 +115,16 @@ _bson_error_message_printf (bson_error_t *error,
115
115
*
116
116
* Side effects:
117
117
* On success, @buffer and @reply_rpc are filled out with the reply.
118
+ * On failure, @error is filled out. If this was a network error
119
+ * and server_id is nonzero, the cluster disconnects from the server.
118
120
*
119
121
*--------------------------------------------------------------------------
120
122
*/
121
123
122
124
bool
123
125
mongoc_cluster_run_command_rpc (mongoc_cluster_t * cluster ,
124
126
mongoc_stream_t * stream ,
127
+ uint32_t server_id ,
125
128
const char * command_name ,
126
129
mongoc_rpc_t * rpc ,
127
130
mongoc_rpc_t * reply_rpc ,
@@ -158,6 +161,9 @@ mongoc_cluster_run_command_rpc (mongoc_cluster_t *cluster,
158
161
cluster -> sockettimeoutms , error ) ||
159
162
!_mongoc_buffer_append_from_stream (buffer , stream , 4 ,
160
163
cluster -> sockettimeoutms , error )) {
164
+
165
+ mongoc_cluster_disconnect_node (cluster , server_id );
166
+
161
167
/* add info about the command to writev_full's error message */
162
168
_mongoc_get_db_name (rpc -> query .collection , db );
163
169
_bson_error_message_printf (
@@ -222,13 +228,16 @@ mongoc_cluster_run_command_rpc (mongoc_cluster_t *cluster,
222
228
*
223
229
* Side effects:
224
230
* @reply is set and should ALWAYS be released with bson_destroy().
231
+ * On failure, @error is filled out. If this was a network error
232
+ * and server_id is nonzero, the cluster disconnects from the server.
225
233
*
226
234
*--------------------------------------------------------------------------
227
235
*/
228
236
229
237
bool
230
238
mongoc_cluster_run_command (mongoc_cluster_t * cluster ,
231
239
mongoc_stream_t * stream ,
240
+ uint32_t server_id ,
232
241
mongoc_query_flags_t flags ,
233
242
const char * db_name ,
234
243
const bson_t * command ,
@@ -249,7 +258,7 @@ mongoc_cluster_run_command (mongoc_cluster_t *cluster,
249
258
_mongoc_rpc_prep_command (& rpc , ns , command , flags );
250
259
251
260
/* we can reuse the query rpc for the reply */
252
- if (!mongoc_cluster_run_command_rpc (cluster , stream ,
261
+ if (!mongoc_cluster_run_command_rpc (cluster , stream , server_id ,
253
262
_mongoc_get_command_name (command ),
254
263
& rpc , & rpc , & buffer , error )) {
255
264
GOTO (done );
@@ -320,7 +329,7 @@ _mongoc_stream_run_ismaster (mongoc_cluster_t *cluster,
320
329
bson_init (& command );
321
330
bson_append_int32 (& command , "ismaster" , 8 , 1 );
322
331
323
- ret = mongoc_cluster_run_command (cluster , stream , MONGOC_QUERY_SLAVE_OK ,
332
+ ret = mongoc_cluster_run_command (cluster , stream , 0 , MONGOC_QUERY_SLAVE_OK ,
324
333
"admin" , & command , reply , error );
325
334
326
335
bson_destroy (& command );
@@ -514,7 +523,7 @@ _mongoc_cluster_auth_node_cr (mongoc_cluster_t *cluster,
514
523
*/
515
524
bson_init (& command );
516
525
bson_append_int32 (& command , "getnonce" , 8 , 1 );
517
- if (!mongoc_cluster_run_command (cluster , stream , MONGOC_QUERY_SLAVE_OK ,
526
+ if (!mongoc_cluster_run_command (cluster , stream , 0 , MONGOC_QUERY_SLAVE_OK ,
518
527
auth_source , & command , & reply , error )) {
519
528
bson_destroy (& command );
520
529
bson_destroy (& reply );
@@ -549,7 +558,7 @@ _mongoc_cluster_auth_node_cr (mongoc_cluster_t *cluster,
549
558
* Execute the authenticate command. mongoc_cluster_run_command
550
559
* checks for {ok: 1} in the response.
551
560
*/
552
- ret = mongoc_cluster_run_command (cluster , stream , MONGOC_QUERY_SLAVE_OK ,
561
+ ret = mongoc_cluster_run_command (cluster , stream , 0 , MONGOC_QUERY_SLAVE_OK ,
553
562
auth_source , & command , & reply , error );
554
563
if (!ret ) {
555
564
/* error->message is already set */
@@ -739,7 +748,7 @@ _mongoc_cluster_auth_node_sasl (mongoc_cluster_t *cluster,
739
748
mongoc_uri_get_username (cluster -> uri ),
740
749
sasl .step );
741
750
742
- if (!mongoc_cluster_run_command (cluster , stream , MONGOC_QUERY_SLAVE_OK ,
751
+ if (!mongoc_cluster_run_command (cluster , stream , 0 , MONGOC_QUERY_SLAVE_OK ,
743
752
"$external" , & cmd , & reply , error )) {
744
753
bson_destroy (& cmd );
745
754
bson_destroy (& reply );
@@ -862,7 +871,7 @@ _mongoc_cluster_auth_node_plain (mongoc_cluster_t *cluster,
862
871
bson_append_utf8 (& b , "payload" , 7 , (const char * )buf , buflen );
863
872
BSON_APPEND_INT32 (& b , "autoAuthorize" , 1 );
864
873
865
- ret = mongoc_cluster_run_command (cluster , stream , MONGOC_QUERY_SLAVE_OK ,
874
+ ret = mongoc_cluster_run_command (cluster , stream , 0 , MONGOC_QUERY_SLAVE_OK ,
866
875
"$external" , & b , & reply , error );
867
876
868
877
if (!ret ) {
@@ -916,7 +925,7 @@ _mongoc_cluster_auth_node_x509 (mongoc_cluster_t *cluster,
916
925
BSON_APPEND_UTF8 (& cmd , "mechanism" , "MONGODB-X509" );
917
926
BSON_APPEND_UTF8 (& cmd , "user" , username );
918
927
919
- ret = mongoc_cluster_run_command (cluster , stream , MONGOC_QUERY_SLAVE_OK ,
928
+ ret = mongoc_cluster_run_command (cluster , stream , 0 , MONGOC_QUERY_SLAVE_OK ,
920
929
"$external" , & cmd , & reply , error );
921
930
922
931
if (!ret ) {
@@ -986,7 +995,7 @@ _mongoc_cluster_auth_node_scram (mongoc_cluster_t *cluster,
986
995
mongoc_uri_get_username (cluster -> uri ),
987
996
scram .step );
988
997
989
- if (!mongoc_cluster_run_command (cluster , stream , MONGOC_QUERY_SLAVE_OK ,
998
+ if (!mongoc_cluster_run_command (cluster , stream , 0 , MONGOC_QUERY_SLAVE_OK ,
990
999
auth_source , & cmd , & reply , error )) {
991
1000
bson_destroy (& cmd );
992
1001
bson_destroy (& reply );
@@ -2035,6 +2044,8 @@ _mongoc_cluster_check_interval (mongoc_cluster_t *cluster,
2035
2044
if (scanner_node -> last_used + (1000 * CHECK_CLOSED_DURATION_MSEC ) < now ) {
2036
2045
if (mongoc_stream_check_closed (stream )) {
2037
2046
mongoc_cluster_disconnect_node (cluster , server_id );
2047
+ bson_set_error (error , MONGOC_ERROR_STREAM , MONGOC_ERROR_STREAM_SOCKET ,
2048
+ "Stream is closed" );
2038
2049
return false;
2039
2050
}
2040
2051
}
@@ -2045,9 +2056,9 @@ _mongoc_cluster_check_interval (mongoc_cluster_t *cluster,
2045
2056
BSON_APPEND_INT32 (& command , "ismaster" , 1 );
2046
2057
2047
2058
before_ismaster = now ;
2048
-
2049
- r = mongoc_cluster_run_command ( cluster , stream , MONGOC_QUERY_SLAVE_OK ,
2050
- "admin" , & command , & reply , error );
2059
+ r = mongoc_cluster_run_command ( cluster , stream , server_id ,
2060
+ MONGOC_QUERY_SLAVE_OK , "admin" , & command ,
2061
+ & reply , error );
2051
2062
2052
2063
now = bson_get_monotonic_time ();
2053
2064
0 commit comments