Skip to content

Commit 3d1669b

Browse files
committed
CDRIVER-696: If the server description knows the last error, use it
1 parent 21c0ea4 commit 3d1669b

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/mongoc/mongoc-cluster.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,10 +1383,10 @@ mongoc_cluster_fetch_stream (mongoc_cluster_t *cluster,
13831383

13841384
/* in the single-threaded use case we share topology's streams */
13851385
if (topology->single_threaded) {
1386+
sd = mongoc_topology_description_server_by_id (&topology->description, server_id);
13861387

13871388
scanner_node = mongoc_topology_scanner_get_node (topology->scanner, server_id);
13881389
if (!scanner_node) {
1389-
sd = mongoc_topology_description_server_by_id (&topology->description, server_id);
13901390
if (sd && sd->error.code) {
13911391
memcpy (error, &sd->error, sizeof *error);
13921392
} else {
@@ -1402,18 +1402,21 @@ mongoc_cluster_fetch_stream (mongoc_cluster_t *cluster,
14021402

14031403
stream = scanner_node->stream;
14041404
if (!stream) {
1405-
bson_set_error (error,
1406-
MONGOC_ERROR_STREAM,
1407-
MONGOC_ERROR_STREAM_NOT_ESTABLISHED,
1408-
"Could not find stream for node %u", server_id);
1405+
if (sd && sd->error.code) {
1406+
memcpy (error, &sd->error, sizeof *error);
1407+
} else {
1408+
bson_set_error (error,
1409+
MONGOC_ERROR_STREAM,
1410+
MONGOC_ERROR_STREAM_NOT_ESTABLISHED,
1411+
"Could not find stream for node %u", server_id);
1412+
}
14091413
GOTO(FETCH_FAIL);
14101414
}
14111415

14121416
/* if stream exists but isn't authed, a disconnect happened */
14131417
if (cluster->requires_auth && !scanner_node->has_auth) {
14141418

14151419
/* try to reconnect and re-authenticate */
1416-
sd = mongoc_topology_description_server_by_id (&topology->description, server_id);
14171420
if (!sd) {
14181421
bson_set_error (error,
14191422
MONGOC_ERROR_STREAM,

tests/test-mongoc-client.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ test_mongoc_client_authenticate_failure (void *context)
180180
assert(!r);
181181
r = mongoc_cursor_error(cursor, &error);
182182
assert(r);
183-
assert(error.domain == MONGOC_ERROR_CLIENT);
184-
assert(error.code == MONGOC_ERROR_CLIENT_AUTHENTICATE);
183+
ASSERT_CMPINT (error.domain, ==, MONGOC_ERROR_CLIENT);
184+
ASSERT_CMPINT (error.code, ==, MONGOC_ERROR_CLIENT_AUTHENTICATE);
185185
mongoc_cursor_destroy(cursor);
186186

187187
/*
@@ -194,8 +194,8 @@ test_mongoc_client_authenticate_failure (void *context)
194194
r = mongoc_collection_insert (collection, MONGOC_INSERT_NONE,
195195
&empty, NULL, &error);
196196
assert (!r);
197-
assert (error.domain == MONGOC_ERROR_CLIENT);
198-
assert (error.code == MONGOC_ERROR_CLIENT_AUTHENTICATE);
197+
ASSERT_CMPINT (error.domain, ==, MONGOC_ERROR_CLIENT);
198+
ASSERT_CMPINT (error.code, ==, MONGOC_ERROR_CLIENT_AUTHENTICATE);
199199

200200
/*
201201
* Try various commands while in the failed state to ensure we get the
@@ -207,8 +207,8 @@ test_mongoc_client_authenticate_failure (void *context)
207207
r = mongoc_collection_update (collection, MONGOC_UPDATE_NONE,
208208
&q, &empty, NULL, &error);
209209
assert (!r);
210-
assert (error.domain == MONGOC_ERROR_CLIENT);
211-
assert (error.code == MONGOC_ERROR_CLIENT_AUTHENTICATE);
210+
ASSERT_CMPINT (error.domain, ==, MONGOC_ERROR_CLIENT);
211+
ASSERT_CMPINT (error.code, ==, MONGOC_ERROR_CLIENT_AUTHENTICATE);
212212

213213
bson_free (host);
214214
bson_free (uri_str_no_auth);

0 commit comments

Comments
 (0)