Skip to content

Commit 9d5bc13

Browse files
committed
CDRIVER-696: Store the topology_scanner node failure so we can report it later
1 parent 2013c9c commit 9d5bc13

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/mongoc/mongoc-cluster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ mongoc_cluster_node_reconnect (mongoc_cluster_t *cluster, uint32_t server_id, bs
12551255

12561256
mongoc_stream_failed (scanner_node->stream);
12571257
scanner_node->stream = NULL;
1258-
mongoc_topology_scanner_node_setup (scanner_node);
1258+
mongoc_topology_scanner_node_setup (scanner_node, error);
12591259
if (scanner_node->stream && cluster->requires_auth) {
12601260
sd = mongoc_topology_server_by_id (topology, server_id);
12611261
if (!sd) {

src/mongoc/mongoc-topology-scanner-private.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef struct mongoc_topology_scanner_node
5656
struct mongoc_topology_scanner_node *prev;
5757

5858
bool retired;
59+
bson_error_t last_error;
5960
} mongoc_topology_scanner_node_t;
6061

6162
typedef struct mongoc_topology_scanner
@@ -116,7 +117,8 @@ void
116117
mongoc_topology_scanner_reset (mongoc_topology_scanner_t *ts);
117118

118119
bool
119-
mongoc_topology_scanner_node_setup (mongoc_topology_scanner_node_t *node);
120+
mongoc_topology_scanner_node_setup (mongoc_topology_scanner_node_t *node,
121+
bson_error_t *error);
120122

121123
mongoc_topology_scanner_node_t *
122124
mongoc_topology_scanner_get_node (mongoc_topology_scanner_t *ts,

src/mongoc/mongoc-topology-scanner.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ mongoc_topology_scanner_add_and_scan (mongoc_topology_scanner_t *ts,
124124

125125
node = mongoc_topology_scanner_add (ts, host, id);
126126

127-
if (node && mongoc_topology_scanner_node_setup (node)) {
127+
if (node && mongoc_topology_scanner_node_setup (node, &node->last_error)) {
128128
node->cmd = mongoc_async_cmd (
129129
ts->async, node->stream, ts->setup,
130130
node->host.host, "admin",
@@ -405,23 +405,22 @@ mongoc_topology_scanner_node_connect_unix (mongoc_topology_scanner_node_t *node,
405405
}
406406

407407
bool
408-
mongoc_topology_scanner_node_setup (mongoc_topology_scanner_node_t *node)
408+
mongoc_topology_scanner_node_setup (mongoc_topology_scanner_node_t *node, bson_error_t *error)
409409
{
410410
mongoc_stream_t *sock_stream;
411-
bson_error_t error = { 0 };
412411

413412
if (node->stream) { return true; }
414413

415414
BSON_ASSERT (!node->retired);
416415

417416
if (node->ts->initiator) {
418417
sock_stream = node->ts->initiator (node->ts->uri, &node->host,
419-
node->ts->initiator_context, &error);
418+
node->ts->initiator_context, error);
420419
} else {
421420
if (node->host.family == AF_UNIX) {
422-
sock_stream = mongoc_topology_scanner_node_connect_unix (node, &error);
421+
sock_stream = mongoc_topology_scanner_node_connect_unix (node, error);
423422
} else {
424-
sock_stream = mongoc_topology_scanner_node_connect_tcp (node, &error);
423+
sock_stream = mongoc_topology_scanner_node_connect_tcp (node, error);
425424
}
426425

427426
#ifdef MONGOC_ENABLE_SSL
@@ -433,7 +432,7 @@ mongoc_topology_scanner_node_setup (mongoc_topology_scanner_node_t *node)
433432

434433
if (!sock_stream) {
435434
/* Pass a rtt of -1 if we couldn't initialize a stream in node_setup */
436-
node->ts->cb (node->id, NULL, -1, node->ts->cb_data, &error);
435+
node->ts->cb (node->id, NULL, -1, node->ts->cb_data, error);
437436
return false;
438437
}
439438

@@ -491,7 +490,7 @@ mongoc_topology_scanner_start (mongoc_topology_scanner_t *ts,
491490
{
492491
/* check node if it last failed before current cooldown period began */
493492
if (node->last_failed < cooldown) {
494-
if (mongoc_topology_scanner_node_setup (node)) {
493+
if (mongoc_topology_scanner_node_setup (node, &node->last_error)) {
495494

496495
BSON_ASSERT (!node->cmd);
497496

0 commit comments

Comments
 (0)