Skip to content

Commit c8cb7ea

Browse files
committed
CDRIVER-696: If the server description knows the last error, use it
1 parent 9d5bc13 commit c8cb7ea

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/mongoc/mongoc-cluster.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,10 +1171,14 @@ _mongoc_cluster_add_node (mongoc_cluster_t *cluster,
11711171
sd->id);
11721172

11731173
if (!scanner_node) {
1174-
bson_set_error (error,
1175-
MONGOC_ERROR_STREAM,
1176-
MONGOC_ERROR_STREAM_NOT_ESTABLISHED,
1177-
"Could not find node %s", sd->connection_address);
1174+
if (sd->error.code) {
1175+
memcpy (error, &sd->error, sizeof *error);
1176+
} else {
1177+
bson_set_error (error,
1178+
MONGOC_ERROR_STREAM,
1179+
MONGOC_ERROR_STREAM_NOT_ESTABLISHED,
1180+
"Could not find node %s", sd->connection_address);
1181+
}
11781182
RETURN (NULL);
11791183
}
11801184

@@ -1363,10 +1367,15 @@ mongoc_cluster_fetch_stream (mongoc_cluster_t *cluster,
13631367

13641368
scanner_node = mongoc_topology_scanner_get_node (topology->scanner, server_id);
13651369
if (!scanner_node) {
1366-
bson_set_error (error,
1367-
MONGOC_ERROR_STREAM,
1368-
MONGOC_ERROR_STREAM_NOT_ESTABLISHED,
1369-
"Could not find node %u", server_id);
1370+
sd = mongoc_topology_description_server_by_id (&topology->description, server_id);
1371+
if (sd && sd->error.code) {
1372+
memcpy (error, &sd->error, sizeof *error);
1373+
} else {
1374+
bson_set_error (error,
1375+
MONGOC_ERROR_STREAM,
1376+
MONGOC_ERROR_STREAM_NOT_ESTABLISHED,
1377+
"Could not find node %u", server_id);
1378+
}
13701379
GOTO(FETCH_FAIL);
13711380
}
13721381

@@ -1396,7 +1405,8 @@ mongoc_cluster_fetch_stream (mongoc_cluster_t *cluster,
13961405

13971406
/* In single-threaded mode, we can use sd's max_wire_version */
13981407
if (!_mongoc_cluster_auth_node (cluster, stream, sd->host.host,
1399-
sd->max_wire_version, error)) {
1408+
sd->max_wire_version, &sd->error)) {
1409+
memcpy (error, &sd->error, sizeof *error);
14001410
GOTO(FETCH_FAIL);
14011411
}
14021412
scanner_node->has_auth = true;

0 commit comments

Comments
 (0)