Skip to content

ares_getaddrinfo(): Fail faster on AF_UNSPEC if we've already received one address class #551

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 4 commits into from
Sep 26, 2023

Conversation

bradh352
Copy link
Member

As per #541, when using AF_UNSPEC with ares_getaddrinfo() (and in turn with ares_gethostbynam()) if we receive a successful response for one address class, we should not allow the other address class to continue on with retries, just return the address class we have.

This will limit the overall query time to whatever timeout remains for the pending query for the other address class, it will not, however, terminate the other query as it may still prove to be successful (possibly coming in less than a millisecond later) and we'd want that result still. It just turns off additional error processing to get the result back quicker.

…l A or AAAA query, tell any other related oustanding queries to not perform any retries if they have issues
/* Identical to ares_send() except returns normal ares return codes like
* ARES_SUCCESS */
int ares_send_ex(ares_channel channel, const unsigned char *qbuf, int qlen,
ares_callback callback, void *arg);
Copy link
Member

Choose a reason for hiding this comment

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

If these two new functions indeed are intended to be added to the public API, then they need man pages as well.

Maybe start out for internal consumption only?

Copy link
Member Author

Choose a reason for hiding this comment

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

They're in the private header. Not sure if they need to be public at all. I just needed to know if there was an error code to know if the query pointer was invalidated by the call or not as otherwise it would cause access to a free'd memory area. In the future we could make them public and add docs for them, but for now they're private.

@@ -248,6 +248,8 @@ struct query {
int using_tcp;
int error_status;
int timeouts; /* number of timeouts we saw for this request */
int no_retries; /* do not perform any additional retries, this is set when
Copy link
Member

Choose a reason for hiding this comment

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

Maybe make it no_retries:1; to signal that it actually is a boolean? Alternatively use a bool typedef.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is another one where "convention" within c-ares gets in the way. There is no bool type defined or used anywhere within c-ares, and I can't find any other instances of using the bitfield width modifiers. You can see the "using_tcp" member above, it too is a boolean, however it too uses no modifiers. I'd rather keep consistency at this point and maybe do a bulk "cleanup" in the future for things like this.

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