[CDRIVER-4593] C Driver fails to validate double type connectionId during handshake process Created: 23/Mar/23 Updated: 28/Oct/23 Resolved: 27/Mar/23 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | libmongoc |
| Affects Version/s: | 1.23.1, 1.23.2 |
| Fix Version/s: | 1.23.3 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Kondaiah Valagonda | Assignee: | Unassigned |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | Bug, linux | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||||||
| Issue Links: |
|
||||||||||||||||
| Quarter: | FY24Q1 | ||||||||||||||||
| Description |
SummaryMongo with higher volume of connections may return connectionId as double during the handshake process. The C(1.23.2) & C++(3.7.x)drivers fail to do a type check for double type connectionId in hello/ismaster response and hence fails to connect to mongo. This happens in clusters with a high volume of connections created at a higher rate and/or without any connection pooling mechanism. db.isMaster() response from mongo shell:
db.isMaster() response from python driver:
The C driver fails to check connectionId value, 3177722651.0 with BSON_ITER_HOLDS_INT EnvironmentC / CXX driver versions:
C / CXX compiler and version:
Mongo:
How to ReproduceIt's difficult to reproduce the issue. Need to create connections at a higher rate to overflow int32 value of connectionId. Temporary FixRestarting the mongo service would reset the connectionId counter.
|
| Comments |
| Comment by Kondaiah Valagonda [ 27/Mar/23 ] | ||||||||
|
Thank you for the update, Kevin | ||||||||
| Comment by Kevin Albertson [ 27/Mar/23 ] | ||||||||
|
Thank you for the fix konda.valagonda@gmail.com. C driver 1.23.3 is planned for release next Tuesday, April 4. | ||||||||
| Comment by Kondaiah Valagonda [ 27/Mar/23 ] | ||||||||
|
@kevin.albertson@mongodb.com | ||||||||
| Comment by Githook User [ 27/Mar/23 ] | ||||||||
|
Author: {'name': 'Kondaiah Valagonda', 'email': '128669292+kvalagonda@users.noreply.github.com', 'username': 'kvalagonda'}Message:
--------- Co-authored-by: Kevin Albertson <kevin.albertson@mongodb.com> | ||||||||
| Comment by Githook User [ 27/Mar/23 ] | ||||||||
|
Author: {'name': 'Kondaiah Valagonda', 'email': '128669292+kvalagonda@users.noreply.github.com', 'username': 'kvalagonda'}Message:
--------- Co-authored-by: Kevin Albertson <kevin.albertson@mongodb.com> | ||||||||
| Comment by Kondaiah Valagonda [ 27/Mar/23 ] | ||||||||
|
Hello, We've submitted the below PR for the C-driver fix. We've tested the fix, and the C-driver is able to handle Int32, Int64, and Double types of connectionIds without any issues. https://github.com/mongodb/mongo-c-driver/pull/1222 Also, The below SERVER ticket has server-side(mongo) bug details. https://jira.mongodb.org/browse/SERVER-75293 Either the [PR|https://github.com/mongodb/mongo-c-driver/pull/1222] or the SERVER ticket has to be fixed. We would prefer to have the fix available in the C-driver first. Please let us know.
Thanks, KV | ||||||||
| Comment by Kondaiah Valagonda [ 24/Mar/23 ] | ||||||||
|
Thank you Jeremy Mikola. The attached Wireshark tcpdump dump also shows that connectionId coming as a Double from a mongos that had a bigger connectionId value, and Int32 from a restarted mongos service. We will submit a SERVER ticket and the PR also with the libmongoc fix.
| ||||||||
| Comment by Jeremy Mikola [ 23/Mar/23 ] | ||||||||
|
Thanks for following up with extended JSON output. Since you're connected to a v4.4.14 sharded cluster, I think the relevant code path may be:
It's still not clear to me where the floating point value is coming from, but if you're confident that the server is responding with a double then I think this may warrant a SERVER ticket (feel free to link back to this for additional context). AFAIK, drivers have only ever expected integer values for connectionId. I don't think changing libmongoc to accept a double would be the best course of action. | ||||||||
| Comment by Kondaiah Valagonda [ 23/Mar/23 ] | ||||||||
|
@jeremy Mikola It's the real double connectionId coming from the mongo hello response and below is the C canonical extended json output of hello().
Used the below snippet in mongoc-server-description.c
Yes,
| ||||||||
| Comment by Jeremy Mikola [ 23/Mar/23 ] | ||||||||
|
I think it's unlikely that the server is returning a double here. Rather, you're seeing a double due to pymongo's JSON output. You might get more accurate results by having pymongo output canonical extended JSON (see: json_util), as that would report type information for 64-bit integers (see: Conversion Table in the Extended JSON spec). The "connectionId" field in the hello/isMaster response is appended in cluster_hello_cmd.cpp. bsonobjbuilder.h does have several overloads for the appendNumber() method, but the argument here is coming from getConnectionId() and is likely a long long according to the typedef earlier in the file. Having said that, this looks related to |