[CDRIVER-587] URI parsing logs warning on w < -1 but otherwise ignores it Created: 20/Mar/15  Updated: 03/May/17  Resolved: 11/Oct/16

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

Type: Bug Priority: Minor - P4
Reporter: Jeremy Mikola Assignee: Backlog - C Driver Team
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CDRIVER-782 Allow more detailed error reporting f... Closed
is related to CDRIVER-580 Write concern with w=0 and j=true is ... Closed
is related to CDRIVER-628 Deprecate MONGOC_WRITE_CONCERN_W_ERRO... Closed

 Description   

While adding validation for journal and w=0 or w=-1 conflict for CDRIVER-580, I noticed that parsing for values of w less than -1 are ignored apart from a logged error. This means that URI parsing can still succeed.

I don't think it's possible to fail during _mongoc_uri_build_write_concern(), which stores parsed options on the write concern struct, as that function provides no API for relaying an error upstream. That's why my PR in CDRIVER-580 validated the write concern one level up in mongoc_uri_new().

That said, I think we could easily catch an invalid w value in mongoc_uri_parse_option(), which does allow us to return false on an error. The relevant code segment would be:

if (*value == '-' || isdigit(*value)) {
   v_int = (int) strtol (value, NULL, 10);
   BSON_APPEND_INT32 (&uri->options, "w", v_int);
}



 Comments   
Comment by A. Jesse Jiryu Davis [ 11/Oct/16 ]

This works as designed.

https://github.com/mongodb/specifications/blob/master/source/connection-string/connection-string-spec.rst

"Any invalid Values for a given key MUST be ignored and MUST log a WARN level message"

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