Skip to content

Commit 4f42685

Browse files
committed
CDRIVER-3116 do not disconnect in mongoc_client_reset
1 parent 654aa1d commit 4f42685

File tree

5 files changed

+13
-43
lines changed

5 files changed

+13
-43
lines changed

src/libmongoc/doc/mongoc_client_reset.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Synopsis
1111
void
1212
mongoc_client_reset (mongoc_client_t *client);
1313
14-
Causes the client to clear its session pool without sending endSessions, and to close all its connections. Call this method in the child after forking.
14+
Call this method in the child after forking.
1515

16-
This method increments an internal generation counter on the given client. After this method is called, cursors from previous generations will not issue a killCursors command when they are destroyed.
16+
This method causes the client to clear its session pool without sending endSessions. It also increments an internal generation counter on the given client. After this method is called, cursors from previous generations will not issue a killCursors command when they are destroyed. Client sessions from previous generations cannot be used and should be destroyed.
1717

1818
Parameters
1919
----------

src/libmongoc/src/mongoc/mongoc-client.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,8 +2974,6 @@ mongoc_client_reset (mongoc_client_t *client)
29742974

29752975
/* Server sessions are owned by us, so we clear the pool on reset. */
29762976
_mongoc_topology_clear_session_pool (client->topology);
2977-
2978-
mongoc_cluster_disconnect (&(client->cluster));
29792977
}
29802978

29812979
mongoc_change_stream_t *

src/libmongoc/src/mongoc/mongoc-cluster-private.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ mongoc_cluster_init (mongoc_cluster_t *cluster,
7878
void
7979
mongoc_cluster_destroy (mongoc_cluster_t *cluster);
8080

81-
void
82-
mongoc_cluster_disconnect (mongoc_cluster_t *cluster);
83-
8481
void
8582
mongoc_cluster_disconnect_node (mongoc_cluster_t *cluster,
8683
uint32_t id,

src/libmongoc/src/mongoc/mongoc-cluster.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,38 +1571,6 @@ _mongoc_cluster_disconnect_node_in_set (uint32_t id, void *item, void *ctx)
15711571
return true;
15721572
}
15731573

1574-
/*
1575-
*--------------------------------------------------------------------------
1576-
*
1577-
* mongoc_cluster_disconnect --
1578-
*
1579-
* Disconnects all nodes in this cluster.
1580-
*
1581-
* Returns:
1582-
* None.
1583-
*
1584-
* Side effects:
1585-
* Clears the cluster's set of nodes and frees them if pooled.
1586-
*
1587-
*--------------------------------------------------------------------------
1588-
*/
1589-
1590-
void
1591-
mongoc_cluster_disconnect (mongoc_cluster_t *cluster)
1592-
{
1593-
mongoc_topology_t *topology;
1594-
1595-
BSON_ASSERT (cluster);
1596-
1597-
topology = cluster->client->topology;
1598-
/* in the single-threaded use case we share topology's streams */
1599-
if (topology->single_threaded) {
1600-
mongoc_topology_scanner_disconnect (topology->scanner);
1601-
} else {
1602-
mongoc_set_for_each_with_id (
1603-
cluster->nodes, _mongoc_cluster_disconnect_node_in_set, cluster);
1604-
}
1605-
}
16061574

16071575
/*
16081576
*--------------------------------------------------------------------------

src/libmongoc/tests/test-mongoc-client.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3574,15 +3574,19 @@ test_client_reset_cursors (void)
35743574
}
35753575

35763576
static bool
3577-
mongoc_topology_scanner_is_disconnected (mongoc_topology_scanner_t *scanner)
3577+
mongoc_topology_scanner_is_connected (mongoc_topology_scanner_t *scanner)
35783578
{
35793579
mongoc_topology_scanner_node_t *node;
35803580

35813581
BSON_ASSERT (scanner);
35823582
node = scanner->nodes;
35833583

3584+
if (!node) {
3585+
return false;
3586+
}
3587+
35843588
while (node) {
3585-
if (node->stream) {
3589+
if (!node->stream) {
35863590
return false;
35873591
}
35883592

@@ -3607,7 +3611,7 @@ test_client_reset_connections (void)
36073611
autoresponder_id = mock_server_auto_ismaster (server, "{ 'isMaster': 1.0 }");
36083612
mock_server_run (server);
36093613

3610-
/* After calling reset, check that connections have been closed. Set
3614+
/* After calling reset, check that connections are left as-is. Set
36113615
heartbeat frequency high, so a background scan won't interfere. */
36123616
uri = mongoc_uri_copy (mock_server_get_uri (server));
36133617
mongoc_uri_set_option_as_int32 (uri, "heartbeatFrequencyMS", 99999);
@@ -3624,9 +3628,12 @@ test_client_reset_connections (void)
36243628
ASSERT (future_get_bool (future));
36253629

36263630
mock_server_remove_autoresponder (server, autoresponder_id);
3631+
3632+
ASSERT (mongoc_topology_scanner_is_connected (client->topology->scanner));
3633+
36273634
mongoc_client_reset (client);
36283635

3629-
ASSERT (mongoc_topology_scanner_is_disconnected (client->topology->scanner));
3636+
ASSERT (mongoc_topology_scanner_is_connected (client->topology->scanner));
36303637

36313638
request_destroy (request);
36323639
future_destroy (future);

0 commit comments

Comments
 (0)