[CDRIVER-589] Driver should sanity check the size of the request document and fail fast Created: 23/Mar/15  Updated: 03/May/17  Resolved: 23/Mar/17

Status: Closed
Project: C Driver
Component/s: Bulk API, libmongoc
Affects Version/s: None
Fix Version/s: 1.7.0

Type: Task Priority: Major - P3
Reporter: Anil Kumar 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:
Depends
is depended on by DRIVERS-275 Drivers should check encoded operatio... Closed
Related
related to CDRIVER-654 Ordered bulk insert continues past ov... Closed
is related to CDRIVER-1023 Support reading 16mb using the new fi... Closed
is related to SERVER-12305 Allow command request and response BS... Backlog

 Description   

The driver should fail fast on document bounds. For large document, i.e. the ones going beyond the 16 MB document limit (or whatever server publishes to be the limits) the server may either return an error or close the connection which leaves the client with a failed socket but without any specific error information based on which it make any intelligent decision to skip documents.

It would be much more efficient if the driver layer can perform the necessary validations in terms of document size etc. The java driver already performs these checks before sending the request to the MongoDB instance.

// CC insert.c -o insert -Isrc/mongoc/ -I src/libbson/src/bson/ -L src/libbson/.libs/ -L .libs/ -lbson -lmongoc-1.0
#include "mongoc.h"
 
const char* const TEST_NS = "test.big_document";
 
int main(int argc, const char* argv[]) {
    mongoc_client_t *client;
    char longStr[5 * 1024*1024] = {};
 
    fprintf(stderr, "Will continue with memsetting the values.\n");
    memset(longStr, 'a', sizeof(longStr));
    longStr[sizeof(longStr) - 1] = '\0';
 
    mongoc_init();
    client = mongoc_client_new("mongodb://127.0.0.1:27017");
    if (!client) {
        fprintf(stderr, "Failed to make client connection to mongod");
        return 1;
    }
 
    fprintf(stderr, "Will continue with creating the object.\n");
 
    bson_t *doc;
    doc = bson_new();
    BSON_APPEND_UTF8(doc, "key_1", longStr);
    BSON_APPEND_UTF8(doc, "key_2", longStr);
    BSON_APPEND_UTF8(doc, "key_3", longStr);
    BSON_APPEND_UTF8(doc, "key_4", longStr);
 
    fprintf(stderr, "Completed creating the document.. will continue with insertion.\n");
    mongoc_collection_t *collection = mongoc_client_get_collection (client, "test", "test");
 
    bson_error_t error;
    if (!mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, NULL, &error)) {
        printf ("%s\n", error.message);
    }
 
    bson_destroy(doc);
    mongoc_collection_destroy(collection);
 
    mongoc_client_destroy(client);
    return 0;
}



 Comments   
Comment by Githook User [ 24/Mar/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-589 test oversized unordered upsert
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/c6ebd2233c04ce6d00d0a25d76b806758b02f682

Comment by Githook User [ 24/Mar/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-589 style in mongoc-write-command.c
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/758adfe9e4f3de25f7c06e15b334b896037d0e52

Comment by A. Jesse Jiryu Davis [ 08/Feb/17 ]

I spoke too soon:

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

Accept this PR with a test and merge for 1.7.0.

Comment by A. Jesse Jiryu Davis [ 05/Jan/17 ]

No reported bugs of this nature in the last year.

Comment by A. Jesse Jiryu Davis [ 08/Jun/15 ]

This may be duplicated by a series of bulk API bugs I've opened in the last month, just need to audit and ensure all paths are tested.

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