Skip to content

Commit d21ab4b

Browse files
committed
CDRIVER-3873 clear fam error on retry (#727)
1 parent d53b3dc commit d21ab4b

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/libmongoc/src/mongoc/mongoc-collection.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3410,6 +3410,11 @@ mongoc_collection_find_and_modify_with_opts (
34103410
done:
34113411
mongoc_server_stream_cleanup (server_stream);
34123412
mongoc_server_stream_cleanup (retry_server_stream);
3413+
3414+
if (ret && error) {
3415+
/* if a retry succeeded, clear the initial error */
3416+
memset (error, 0, sizeof (bson_error_t));
3417+
}
34133418
mongoc_cmd_parts_cleanup (&parts);
34143419
bson_destroy (&command);
34153420
if (&reply_local == reply_ptr) {

src/libmongoc/tests/test-mongoc-collection.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6350,6 +6350,59 @@ test_remove_multi (void)
63506350
mongoc_client_destroy (client);
63516351
}
63526352

6353+
static void
6354+
test_fam_no_error_on_retry (void *unused)
6355+
{
6356+
mongoc_client_t *client;
6357+
mongoc_collection_t *coll;
6358+
bson_error_t error = {0};
6359+
bool ret;
6360+
bson_t reply;
6361+
mongoc_find_and_modify_opts_t *opts;
6362+
6363+
client = test_framework_client_new ();
6364+
ret = mongoc_client_command_simple (
6365+
client,
6366+
"admin",
6367+
tmp_bson ("{'configureFailPoint': 'failCommand', 'mode': {'times': 1}, "
6368+
"'data': {'failCommands': ['findAndModify'], 'errorLabels': "
6369+
"['RetryableWriteError']}}"),
6370+
NULL,
6371+
&reply,
6372+
&error);
6373+
6374+
if (!ret) {
6375+
test_error ("configureFailPoint error: %s reply: %s",
6376+
error.message,
6377+
bson_as_canonical_extended_json (&reply, NULL));
6378+
}
6379+
6380+
coll = get_test_collection (client, BSON_FUNC);
6381+
opts = mongoc_find_and_modify_opts_new ();
6382+
mongoc_find_and_modify_opts_set_update (opts,
6383+
tmp_bson ("{'$set': {'x': 2}}"));
6384+
bson_destroy (&reply);
6385+
ret = mongoc_collection_find_and_modify_with_opts (
6386+
coll, tmp_bson ("{'x': 1}"), opts, &reply, &error);
6387+
if (!ret) {
6388+
test_error (
6389+
"findAndModify error: %s reply: %s", error.message, bson_as_canonical_extended_json (&reply, NULL));
6390+
}
6391+
6392+
if (error.code != 0 || error.domain != 0 ||
6393+
0 != strcmp (error.message, "")) {
6394+
test_error ("error set, but findAndModify succeeded: code=%" PRIu32
6395+
" domain=%" PRIu32 " message=%s",
6396+
error.code,
6397+
error.domain,
6398+
error.message);
6399+
}
6400+
6401+
bson_destroy (&reply);
6402+
mongoc_collection_destroy (coll);
6403+
mongoc_client_destroy (client);
6404+
mongoc_find_and_modify_opts_destroy (opts);
6405+
}
63536406

63546407
void
63556408
test_collection_install (TestSuite *suite)
@@ -6594,4 +6647,11 @@ test_collection_install (TestSuite *suite)
65946647
NULL,
65956648
NULL,
65966649
test_framework_skip_if_not_replset);
6650+
TestSuite_AddFull (suite,
6651+
"/Collection/fam/no_error_on_retry",
6652+
test_fam_no_error_on_retry,
6653+
NULL,
6654+
NULL,
6655+
test_framework_skip_if_no_failpoint,
6656+
test_framework_skip_if_max_wire_version_more_than_9);
65976657
}

0 commit comments

Comments
 (0)