Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-error-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@ _mongoc_error_is_server (const bson_error_t *error);
bool
_mongoc_error_is_auth (const bson_error_t *error);

/* Try to append `s` to `error`. Truncates `s` if `error` is out of space. */
void
_mongoc_error_append (bson_error_t *error, const char *s);

BSON_END_DECLS
9 changes: 9 additions & 0 deletions src/libmongoc/src/mongoc/mongoc-error.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,12 @@ _mongoc_error_is_auth (const bson_error_t *error)

return error->domain == MONGOC_ERROR_CLIENT && error->code == MONGOC_ERROR_CLIENT_AUTHENTICATE;
}

void
_mongoc_error_append (bson_error_t *error, const char *s)
{
BSON_ASSERT (error);
const size_t error_len = strlen (error->message);
const size_t remaining = sizeof (error->message) - error_len;
bson_strncpy (error->message + error_len, s, remaining);
}
12 changes: 8 additions & 4 deletions src/libmongoc/src/mongoc/mongoc-topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,9 @@ mongoc_topology_select_server_id (mongoc_topology_t *topology,
uint32_t server_id;
mc_shared_tpld td = mc_tpld_take_ref (topology);

bson_string_t *topology_type = bson_string_new (". Topology type: ");
bson_string_append (topology_type, mongoc_topology_description_type (td.ptr));

/* These names come from the Server Selection Spec pseudocode */
int64_t loop_start; /* when we entered this function */
int64_t loop_end; /* when we last completed a loop (single-threaded) */
Expand Down Expand Up @@ -1153,10 +1156,7 @@ mongoc_topology_select_server_id (mongoc_topology_t *topology,

if (scan_ready > expire_at && !try_once) {
/* selection timeout will expire before min heartbeat passes */
_mongoc_server_selection_error ("No suitable servers found: "
"`serverselectiontimeoutms` timed out",
&scanner_error,
error);
_mongoc_server_selection_error (timeout_msg, &scanner_error, error);

server_id = 0;
goto done;
Expand Down Expand Up @@ -1301,6 +1301,10 @@ mongoc_topology_select_server_id (mongoc_topology_t *topology,
}

done:
if (error) {
_mongoc_error_append (error, topology_type->str);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If error is non-NULL and an error was not set, I expect this is appending to an uninitialized bson_error_t. This may have been the cause of the Windows task failures.

}
bson_string_free (topology_type, true);
mc_tpld_drop_ref (&td);
return server_id;
}
Expand Down
12 changes: 8 additions & 4 deletions src/libmongoc/tests/test-mongoc-server-selection-errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ test_server_selection_error_dns_direct_single (void)
{
server_selection_error_dns ("mongodb://example-localhost.invalid:27017/",
"No suitable servers found (`serverSelectionTryOnce` set): "
"[Fake error for 'example-localhost.invalid']",
"[Fake error for 'example-localhost.invalid']"
". Topology type: Single",
false,
false);
}
Expand All @@ -93,7 +94,8 @@ test_server_selection_error_dns_direct_pooled (void *ctx)

server_selection_error_dns ("mongodb://example-localhost.invalid:27017/",
"No suitable servers found: `serverSelectionTimeoutMS` expired: "
"[Fake error for 'example-localhost.invalid']",
"[Fake error for 'example-localhost.invalid']"
". Topology type: Single",
false,
true);
}
Expand All @@ -105,7 +107,8 @@ test_server_selection_error_dns_multi_fail_single (void)
"example-localhost.invalid:27017,other-example-localhost.invalid:27017/",
"No suitable servers found (`serverSelectionTryOnce` set):"
" [Fake error for 'example-localhost.invalid']"
" [Fake error for 'other-example-localhost.invalid']",
" [Fake error for 'other-example-localhost.invalid']"
". Topology type: Unknown",
false,
false);
}
Expand All @@ -119,7 +122,8 @@ test_server_selection_error_dns_multi_fail_pooled (void *ctx)
"example-localhost.invalid:27017,other-example-localhost.invalid:27017/",
"No suitable servers found: `serverSelectionTimeoutMS` expired:"
" [Fake error for 'example-localhost.invalid']"
" [Fake error for 'other-example-localhost.invalid']",
" [Fake error for 'other-example-localhost.invalid']"
". Topology type: Unknown",
false,
true);
}
Expand Down