Skip to content

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

Merged
merged 2 commits into from
Jul 1, 2021

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Jun 29, 2021

CDRIVER-4028

I'll backport the resulting commit to r1.17 after merging.

@alcaeus alcaeus requested a review from jmikola June 29, 2021 11:58
@alcaeus alcaeus self-assigned this Jun 29, 2021
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

LGTM. One question about the default switch case and another about relying on h_errno to be declared, but I don't expect the answers to those questions will warrant any changes here.

return "A temporary error occurred on an authoritative name server. Try "
"again later.";
default:
return "An unknown error occurred.";
Copy link
Member

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.

Copy link
Member Author

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.

@@ -328,7 +347,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));
Copy link
Member

Choose a reason for hiding this comment

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

I'm trusting that h_errno is always set by this point. I do find it odd that we rely on it being declared and reference it here even if both DNS APIs used above (which would set this) are unavailable. Or would libmongoc never compile without at least one of those available?

I left some more general comments about using h_errno in CDRIVER-4028, but that's outside the scope of this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Quoting from the resolver(3) man page:

In the case of an error return from res_nquery(), res_query(), res_nsearch(), res_search(), res_nquerydomain(), or res_querydomain(), the global variable h_errno (see gethostbyname(3)) can be consulted to determine the cause of the error.

@@ -306,7 +306,6 @@ _mongoc_hstrerror (int code)
case HOST_NOT_FOUND:
return "The specified host is unknown.";
case NO_ADDRESS:
case NO_DATA:
Copy link
Member

Choose a reason for hiding this comment

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

Is this guaranteed to have the same value as NO_ADDRESS? I assume you caught this in some CI warning?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. I added both constants to ensure we're grabbing it, but CI complained about the case being duplicated. I'd argue that using one of these should be sufficient, and the 50:50 joker picked NO_DATA for elimination. I don't anticipate trouble from this, but I suppose a last resort to deal with either constant not being defined would be to hardcode the value (4) and be done with it.

@alcaeus alcaeus merged commit e37552d into mongodb:master Jul 1, 2021
@alcaeus alcaeus deleted the cdriver-4028 branch July 1, 2021 07:00
alcaeus added a commit that referenced this pull request Jul 1, 2021
)

* Print correct error message when DNS resolution fails

* Drop duplicate case value
@alcaeus
Copy link
Member Author

alcaeus commented Jul 1, 2021

Cherry-picked to r1.17 in e1be09a.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants