[CDRIVER-4622] OP_QUERY egress counter may overcount Created: 21/Apr/23  Updated: 28/Oct/23  Resolved: 03/May/23

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.24.0

Type: Bug Priority: Minor - P4
Reporter: Kevin Albertson Assignee: Ezra Chung
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CDRIVER-4121 Use OP_MSG to authenticate if server ... Closed
related to CDRIVER-4629 Remove code paths that assume maxWire... Closed
is related to CDRIVER-4193 Require hello command for connection ... Closed

 Description   

Proposal

Only increment egress OP_QUERY counter for each command sent. Do not increment egress OP_QUERY counter for each resolved DNS record. This may result in overcounting.

Background

_mongoc_rpc_gather increments the egress OP_QUERY counter

_mongoc_rpc_gather may be called when constructing hello commands for each DNS record in mongoc_topology_scanner_node_setup_tcp:

LL_FOREACH2 (node->dns_results, iter, ai_next)
{
    _begin_hello_cmd (node,
                    NULL /* stream */,
                    false /* is_setup_done */,
                    iter,
                    delay,
                    true /* use_handshake */);
    /* each subsequent DNS result will have an additional 250ms delay. */
    delay += HAPPY_EYEBALLS_DELAY_MS;
}

_mongoc_rpc_gather is called through this call path:

test-libmongoc!_mongoc_rpc_gather (/Users/kevin.albertson/review/mongo-c-driver-1242/src/libmongoc/src/mongoc/mongoc-rpc.c:606)
test-libmongoc!_mongoc_async_cmd_init_send (/Users/kevin.albertson/review/mongo-c-driver-1242/src/libmongoc/src/mongoc/mongoc-async-cmd.c:168)
test-libmongoc!mongoc_async_cmd_new (/Users/kevin.albertson/review/mongo-c-driver-1242/src/libmongoc/src/mongoc/mongoc-async-cmd.c:232)
test-libmongoc!_begin_hello_cmd (/Users/kevin.albertson/review/mongo-c-driver-1242/src/libmongoc/src/mongoc/mongoc-topology-scanner.c:431)
test-libmongoc!mongoc_topology_scanner_node_setup_tcp (/Users/kevin.albertson/review/mongo-c-driver-1242/src/libmongoc/src/mongoc/mongoc-topology-scanner.c:975)

The egress OP_QUERY counter is documented as "The number of sent Query operations."

The expected behavior is to only increment egress OP_QUERY when an OP_QUERY is sent, not just constructed.

Here is a test that shows the issue:

static void
test_overcounting_opquery (void *unused)
{
   BSON_UNUSED (unused);
 
   bson_error_t error = {0};
   // Connect to exactly one host that resolves to both IPv4 and IPv6.
   mongoc_client_t *const client = mongoc_client_new ("mongodb://ipv4_and_ipv6.test.build.10gen.cc:27017");
 
   mongoc_counter_op_egress_query_reset ();
 
   ASSERT_OR_PRINT (
      mongoc_client_get_server_status (client, NULL, NULL, &error), error);
 
   const int32_t sent_queries = mongoc_counter_op_egress_query_count ();
   // Expect one OP_QUERY for handshake.
   ASSERT_WITH_MSG (
      sent_queries == 1,
      "expected exactly one OP_QUERY requests, but observed %" PRId32
      " requests",
      sent_queries);
   // May fail with: 'expected exactly one OP_QUERY requests, but observed 2
   // requests' if 'localhost' resolves to more than one DNS record.
   mongoc_client_destroy (client);
}

For assistance with testing:

  • localhost.test.build.10gen.cc only resolves to IPv4 127.0.0.1
  • ipv4_and_ipv6.test.build.10gen.cc resolves to both IPv4 12 127.0.0.1 and IPv6 ::1


 Comments   
Comment by Githook User [ 03/May/23 ]

Author:

{'name': 'Ezra Chung', 'email': '88335979+eramongodb@users.noreply.github.com', 'username': 'eramongodb'}

Message: CDRIVER-4193 Ensure OP_MSG for handshakes and fix RPC op_egress counters (#1256)

  • Move SHM count function into mongoc-counters-private.h
  • Declare test_framework_has_compressors in test-libmongoc.h
  • Allow /counters/op_msg and /counters/op_compressed with auth
  • Add _mongoc_rpc_op_egress_inc
  • CDRIVER-4193 RTT thread should also use hello if serverApi is given
  • Do not increment RPC op_egress counters in mock server
  • Add /counters/rpc/op_egress tests
  • CDRIVER-4622 RPC op_egress increment: mongoc_async_cmd_new -> mongoc_async_cmd_phase_send
  • Add mongoc_<object>_uses_loadbalanced
  • CDRIVER-4265 Use OP_MSG for handshakes when loadBalanced=true
Generated at Wed Feb 07 21:21:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.