Skip to content

Commit a835747

Browse files
committed
CDRIVER-1522 don't send maxAwaitTimeMS to server
1 parent b14c511 commit a835747

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/mongoc/mongoc-cursor.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,14 +976,16 @@ _mongoc_cursor_parse_opts_for_op_query (mongoc_cursor_t *cursor,
976976
}
977977
/* singleBatch limit and batchSize are handled in _mongoc_n_return,
978978
* exhaust noCursorTimeout oplogReplay tailable in _mongoc_cursor_flags
979+
* maxAwaitTimeMS is handled in _mongoc_cursor_prepare_getmore_command
979980
*/
980981
else if (strcmp (key, SINGLE_BATCH) &&
981982
strcmp (key, LIMIT) &&
982983
strcmp (key, BATCH_SIZE) &&
983984
strcmp (key, EXHAUST) &&
984985
strcmp (key, NO_CURSOR_TIMEOUT) &&
985986
strcmp (key, OPLOG_REPLAY) &&
986-
strcmp (key, TAILABLE)) {
987+
strcmp (key, TAILABLE) &&
988+
strcmp (key, MAX_AWAIT_TIME_MS)) {
987989
/* pass unrecognized options to server, prefixed with $ */
988990
PUSH_DOLLAR_QUERY ();
989991
dollar_modifier = bson_strdup_printf ("$%s", key);
@@ -1311,11 +1313,24 @@ _mongoc_cursor_prepare_find_command (mongoc_cursor_t *cursor,
13111313
{
13121314
const char *collection;
13131315
int collection_len;
1316+
bson_iter_t iter;
13141317

13151318
_mongoc_cursor_collection (cursor, &collection, &collection_len);
13161319
bson_append_utf8 (command, FIND, FIND_LEN, collection, collection_len);
13171320
bson_append_document (command, FILTER, FILTER_LEN, &cursor->filter);
1318-
bson_concat (command, &cursor->opts);
1321+
bson_iter_init (&iter, &cursor->opts);
1322+
1323+
while (bson_iter_next (&iter)) {
1324+
/* don't append "maxAwaitTimeMS" */
1325+
if (strcmp (bson_iter_key (&iter), MAX_AWAIT_TIME_MS)) {
1326+
if (!bson_append_iter (command, bson_iter_key (&iter), -1, &iter)) {
1327+
bson_set_error (&cursor->error, MONGOC_ERROR_BSON,
1328+
MONGOC_ERROR_BSON_INVALID, "Cursor opts too large");
1329+
MARK_FAILED (cursor);
1330+
return false;
1331+
}
1332+
}
1333+
}
13191334

13201335
if (cursor->read_concern->level != NULL) {
13211336
const bson_t *read_concern_bson;

tests/test-mongoc-collection-find-with-opts.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,10 @@ test_getmore_cmd_await (void)
642642
future = future_cursor_next (cursor, &doc);
643643
request = mock_server_receives_command (
644644
server, "db", MONGOC_QUERY_SLAVE_OK,
645-
"{'find': 'collection', 'filter': {}}");
645+
"{'find': 'collection',"
646+
" 'filter': {},"
647+
" 'maxTimeMS': {'$exists': false},"
648+
" 'maxAwaitTimeMS': {'$exists': false}}");
646649

647650
ASSERT (request);
648651
mock_server_replies_simple (request, "{'ok': 1,"
@@ -663,6 +666,7 @@ test_getmore_cmd_await (void)
663666
server, "db", MONGOC_QUERY_SLAVE_OK,
664667
"{'getMore': {'$numberLong': '123'},"
665668
" 'collection': 'collection',"
669+
" 'maxAwaitTimeMS': {'$exists': false},"
666670
" 'maxTimeMS': {'$numberLong': '9999'}}}");
667671

668672
ASSERT (request);

tests/test-mongoc-collection-find.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,12 @@ test_getmore_await (void)
999999
future = future_cursor_next (cursor, &doc);
10001000

10011001
/* only the slave ok bit is still in the query header */
1002-
request = mock_server_receives_command (server, "db",
1003-
MONGOC_QUERY_SLAVE_OK,
1004-
"{'find': 'collection'}");
1002+
request = mock_server_receives_command (
1003+
server, "db",
1004+
MONGOC_QUERY_SLAVE_OK,
1005+
"{'find': 'collection',"
1006+
" 'maxTimeMS': {'$exists': false},"
1007+
" 'maxAwaitTimeMS': {'$exists': false}}");
10051008

10061009
/* reply with cursor id 1 */
10071010
mock_server_replies_simple (request, "{'ok': 1,"
@@ -1031,6 +1034,7 @@ test_getmore_await (void)
10311034
MONGOC_QUERY_SLAVE_OK,
10321035
"{'getMore': {'$numberLong': '1'},"
10331036
" 'collection': 'collection',"
1037+
" 'maxAwaitTimeMS': {'$exists': false},"
10341038
" 'maxTimeMS': %s}",
10351039
max_time_json);
10361040

0 commit comments

Comments
 (0)