@@ -929,6 +929,61 @@ test_rtt (void *ctx)
929
929
}
930
930
931
931
932
+ /* mongoc_topology_scanner_add_and_scan is called within the topology mutex, it
933
+ * adds a discovered node and calls getaddrinfo on its host immediately - test
934
+ * that this doesn't cause a recursive acquire on the topology mutex */
935
+ static void
936
+ test_add_and_scan_failure (void )
937
+ {
938
+ mock_server_t * server ;
939
+ mongoc_uri_t * uri ;
940
+ mongoc_client_pool_t * pool ;
941
+ mongoc_client_t * client ;
942
+ future_t * future ;
943
+ request_t * request ;
944
+ bson_error_t error ;
945
+ mongoc_server_description_t * sd ;
946
+
947
+ server = mock_server_new ();
948
+ mock_server_run (server );
949
+ /* client will discover "fake" host and fail to connect */
950
+ mock_server_auto_ismaster (server ,
951
+ "{'ok': 1,"
952
+ " 'ismaster': true,"
953
+ " 'setName': 'rs',"
954
+ " 'hosts': ['%s', 'fake:1']}" ,
955
+ mock_server_get_host_and_port (server ));
956
+
957
+ uri = mongoc_uri_copy (mock_server_get_uri (server ));
958
+ mongoc_uri_set_option_as_utf8 (uri , "replicaSet" , "rs" );
959
+ pool = mongoc_client_pool_new (uri );
960
+ client = mongoc_client_pool_pop (pool );
961
+ future = future_client_command_simple (client , "db" ,
962
+ tmp_bson ("{'ping': 1}" ),
963
+ NULL , NULL , & error );
964
+
965
+ request = mock_server_receives_command (server , "db" , MONGOC_QUERY_NONE ,
966
+ "{'ping': 1}" );
967
+ mock_server_replies_ok_and_destroys (request );
968
+ ASSERT_OR_PRINT (future_get_bool (future ), error );
969
+
970
+ sd = mongoc_topology_server_by_id (client -> topology , 1 , NULL );
971
+ ASSERT (sd );
972
+ ASSERT_CMPSTR (mongoc_server_description_type (sd ), "RSPrimary" );
973
+ mongoc_server_description_destroy (sd );
974
+
975
+ sd = mongoc_topology_server_by_id (client -> topology , 2 , NULL );
976
+ ASSERT (sd );
977
+ ASSERT_CMPSTR (mongoc_server_description_type (sd ), "Unknown" );
978
+ mongoc_server_description_destroy (sd );
979
+
980
+ future_destroy (future );
981
+ mongoc_client_pool_push (pool , client );
982
+ mongoc_client_pool_destroy (pool );
983
+ mongoc_uri_destroy (uri );
984
+ mock_server_destroy (server );
985
+ }
986
+
932
987
void
933
988
test_topology_install (TestSuite * suite )
934
989
{
@@ -967,4 +1022,6 @@ test_topology_install (TestSuite *suite)
967
1022
test_server_removed_during_handshake_pooled );
968
1023
TestSuite_AddFull (suite , "/Topology/rtt" , test_rtt , NULL , NULL ,
969
1024
test_framework_skip_if_slow );
1025
+ TestSuite_AddLive (suite , "/Topology/add_and_scan_failure" ,
1026
+ test_add_and_scan_failure );
970
1027
}
0 commit comments