[CDRIVER-4499] mongoc_server_description_handle_hello does not always set error when hello response is malformed Created: 12/Oct/22  Updated: 28/Oct/23  Resolved: 21/Oct/22

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

Type: Bug Priority: Unknown
Reporter: Andreas Braun Assignee: Gil Alon
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by CDRIVER-4360 Improve server description's hello ha... Closed
Related
related to CDRIVER-4502 libmongoc expects connectionId in hel... Closed
Backwards Compatibility: Fully Compatible

 Description   

Summary

When iterating through the hello response, mongoc_server_description_handle_hello does not set the bson_error_t on the server description if the type check on any fields fails. This causes further errors down the line due to _cluster_fetch_stream_single returning the server description's error if it selects a server with a type of MONGOC_SERVER_UNKNOWN. Since this error is not set, any operation that calls fails with an unknown error.

Environment

Versions starting with 1.22.0 are affected when connecting to a mongohoused. In my case, connecting to mongohoused returned a hello response which contained a connectionId with type int64, whereas libmongoc expects int32 for a connectionId.

How to Reproduce

The hello response that triggered this behaviour is as follows:

{ 
  "ok" : { "$numberInt" : "1" }, 
  "ismaster" : true, 
  "maxBsonObjectSize" : { "$numberInt" : "16777216" }, 
  "maxMessageSizeBytes" : { "$numberInt" : "48000000" }, 
  "maxWriteBatchSize" : { "$numberInt" : "100000" }, 
  "logicalSessionTimeoutMinutes" : { "$numberInt" : "30" }, 
  "connectionId" : { "$numberLong" : "565160423" }, 
  "minWireVersion" : { "$numberInt" : "0" }, 
  "maxWireVersion" : { "$numberInt" : "15" }, 
  "readOnly" : false 
}

Expected behaviour

When setting the server description's type to unknown, the associated bson_error_t should contain a reason for why the server was marked as unknown. This is not the case for validation failures in the hello response.



 Comments   
Comment by Githook User [ 27/Mar/23 ]

Author:

{'name': 'Gil Alon', 'email': '47804748+galon1@users.noreply.github.com', 'username': 'galon1'}

Message: CDRIVER-4499 Set bson_error when hello response is malformed (#1129)

CDRIVER-4499 add bson_set_error to invalid types in handle hello
Branch: r1.23
https://github.com/mongodb/mongo-c-driver/commit/bb9526c1402b7b84c61d6278273543bc5bbb07cc

Comment by Githook User [ 21/Oct/22 ]

Author:

{'name': 'Gil Alon', 'email': '47804748+galon1@users.noreply.github.com', 'username': 'galon1'}

Message: CDRIVER-4499 Set bson_error when hello response is malformed (#1129)

CDRIVER-4499 add bson_set_error to invalid types in handle hello
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/b6dad0ccb4ba2e1dfd3f4453a01ec440487af563

Comment by Gil Alon [ 20/Oct/22 ]

PR: https://github.com/mongodb/mongo-c-driver/pull/1129

Generated at Wed Feb 07 21:21:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.