Skip to content

Commit 6bfa232

Browse files
committed
CDRIVER-3405 change stream after retryable error fails
1 parent 1d49210 commit 6bfa232

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/libmongoc/src/mongoc/mongoc-client.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,6 +1654,11 @@ _mongoc_client_retryable_write_command_with_stream (
16541654
mongoc_server_stream_cleanup (retry_server_stream);
16551655
}
16561656

1657+
if (ret && error) {
1658+
/* if a retry succeeded, clear the initial error */
1659+
memset (error, 0, sizeof (bson_error_t));
1660+
}
1661+
16571662
RETURN (ret);
16581663
}
16591664

@@ -1719,6 +1724,11 @@ _mongoc_client_retryable_read_command_with_stream (
17191724
mongoc_server_stream_cleanup (retry_server_stream);
17201725
}
17211726

1727+
if (ret && error) {
1728+
/* if a retry succeeded, clear the initial error */
1729+
memset (error, 0, sizeof (bson_error_t));
1730+
}
1731+
17221732
RETURN (ret);
17231733
}
17241734

src/libmongoc/tests/json-test-operations.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717

1818
#include "bson/bson.h"
1919

20+
#include "mongoc/mongoc-change-stream-private.h"
2021
#include "mongoc/mongoc-collection-private.h"
2122
#include "mongoc/mongoc-config.h"
2223
#include "mongoc/mongoc-cursor-private.h"
2324
#include "mongoc/mongoc-host-list-private.h"
2425
#include "mongoc/mongoc-server-description-private.h"
2526
#include "mongoc/mongoc-topology-description-private.h"
2627
#include "mongoc/mongoc-topology-private.h"
27-
#include "mongoc/mongoc-util-private.h"
28-
#include "mongoc/mongoc-util-private.h"
2928
#include "mongoc/mongoc-uri-private.h"
29+
#include "mongoc/mongoc-util-private.h"
3030

3131
#include "json-test-operations.h"
3232
#include "json-test.h"
@@ -1759,6 +1759,13 @@ gridfs_download (mongoc_database_t *db,
17591759
return true;
17601760
}
17611761

1762+
static bool
1763+
op_error (const bson_t *operation)
1764+
{
1765+
return bson_has_field (operation, "error") &&
1766+
bson_lookup_bool (operation, "error");
1767+
}
1768+
17621769
bool
17631770
json_test_operation (json_test_ctx_t *ctx,
17641771
const bson_t *test,
@@ -1844,6 +1851,13 @@ json_test_operation (json_test_ctx_t *ctx,
18441851
bson_t pipeline = BSON_INITIALIZER;
18451852
mongoc_change_stream_destroy (ctx->change_stream);
18461853
ctx->change_stream = mongoc_collection_watch (c, &pipeline, NULL);
1854+
res = (op_error (operation) == (bool) ctx->change_stream->err.code);
1855+
if (!res) {
1856+
test_error ("expected error=%s, but actual error='%s'",
1857+
op_error (operation) ? "true" : "false",
1858+
ctx->change_stream->err.message);
1859+
}
1860+
18471861
bson_init (reply);
18481862
bson_destroy (&pipeline);
18491863
} else if (!strcmp (op_name, "mapReduce") ||
@@ -1865,6 +1879,13 @@ json_test_operation (json_test_ctx_t *ctx,
18651879
bson_t pipeline = BSON_INITIALIZER;
18661880
mongoc_change_stream_destroy (ctx->change_stream);
18671881
ctx->change_stream = mongoc_database_watch (db, &pipeline, NULL);
1882+
res = (op_error (operation) == (bool) ctx->change_stream->err.code);
1883+
if (!res) {
1884+
test_error ("expected error=%s, but actual error='%s'",
1885+
op_error (operation) ? "true" : "false",
1886+
ctx->change_stream->err.message);
1887+
}
1888+
18681889
bson_init (reply);
18691890
bson_destroy (&pipeline);
18701891
} else if (!strcmp (op_name, "listCollectionObjects")) {
@@ -1912,6 +1933,13 @@ json_test_operation (json_test_ctx_t *ctx,
19121933
bson_t pipeline = BSON_INITIALIZER;
19131934
mongoc_change_stream_destroy (ctx->change_stream);
19141935
ctx->change_stream = mongoc_client_watch (c->client, &pipeline, NULL);
1936+
res = (op_error (operation) == (bool) ctx->change_stream->err.code);
1937+
if (!res) {
1938+
test_error ("expected error=%s, but actual error='%s'",
1939+
op_error (operation) ? "true" : "false",
1940+
ctx->change_stream->err.message);
1941+
}
1942+
19151943
bson_init (reply);
19161944
bson_destroy (&pipeline);
19171945
} else if (!strcmp (op_name, "listDatabaseObjects")) {

src/libmongoc/tests/test-conveniences.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ bson_lookup_doc (const bson_t *b, const char *key, bson_t *doc);
6565
void
6666
bson_lookup_doc_null_ok (const bson_t *b, const char *key, bson_t *doc);
6767

68+
bool
69+
bson_lookup_bool (const bson_t *b, const char *key);
70+
6871
int32_t
6972
bson_lookup_int32 (const bson_t *b, const char *key);
7073

0 commit comments

Comments
 (0)