-
Notifications
You must be signed in to change notification settings - Fork 455
CDRIVER-4028 Print correct error message when DNS resolution fails #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -299,6 +299,24 @@ typedef bool (*mongoc_rr_callback_t) (const char *service, | |
mongoc_rr_data_t *rr_data, | ||
bson_error_t *error); | ||
|
||
static const char * | ||
_mongoc_hstrerror (int code) | ||
{ | ||
switch (code) { | ||
case HOST_NOT_FOUND: | ||
return "The specified host is unknown."; | ||
case NO_ADDRESS: | ||
return "The requested name is valid but does not have an IP address."; | ||
case NO_RECOVERY: | ||
return "A nonrecoverable name server error occurred."; | ||
case TRY_AGAIN: | ||
return "A temporary error occurred on an authoritative name server. Try " | ||
"again later."; | ||
default: | ||
return "An unknown error occurred."; | ||
} | ||
} | ||
|
||
static bool | ||
srv_callback (const char *service, | ||
ns_msg *ns_answer, | ||
|
@@ -328,7 +346,7 @@ srv_callback (const char *service, | |
if (size < 1) { | ||
DNS_ERROR ("Invalid record in SRV answer for \"%s\": \"%s\"", | ||
service, | ||
strerror (h_errno)); | ||
_mongoc_hstrerror (h_errno)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trusting that I left some more general comments about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quoting from the resolver(3) man page:
|
||
} | ||
|
||
if (!_mongoc_host_list_from_hostport_with_err ( | ||
|
@@ -474,7 +492,7 @@ _mongoc_get_rr_search (const char *service, | |
DNS_ERROR ("Failed to look up %s record \"%s\": %s", | ||
rr_type_name, | ||
service, | ||
strerror (h_errno)); | ||
_mongoc_hstrerror (h_errno)); | ||
} | ||
} while (size >= buffer_size); | ||
|
||
|
@@ -495,7 +513,7 @@ _mongoc_get_rr_search (const char *service, | |
i, | ||
rr_type_name, | ||
service, | ||
strerror (h_errno)); | ||
_mongoc_hstrerror (h_errno)); | ||
} | ||
|
||
/* Skip records that don't match the ones we requested. CDRIVER-3628 shows | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice, would we ever hit this case? If so, I wonder if it'd be helpful to somehow expose the integer value in the error message relayed up the chain. I realize we can't print the value of
code
here since it'd require allocating a string, but perhaps we can do this in the calling context.If it's unlikely we'd hit this case, I'm fine leaving it as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of it but avoided it because it would require allocating memory. Either way, even if we hit this scenario, it would be difficult for us to do anything as the value given would not make any sense to us (since it isn't documented). Even with the code, we'd most likely have to resort to tracing or other means to find out what's going on so I opted for this message.