-
Notifications
You must be signed in to change notification settings - Fork 2k
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
sock_dns: implement DNS cache #17680
Conversation
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.
Looks good to me in general :) See a couple of comments below.
046b54b
to
e5b68e3
Compare
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.
Nice one, I should have a look at the new PRs more often. I tested this PR with #17494 (without the topmost fixup commit) on esp32-wroom-32
so I can can query a specific IP versions. Works like a charm, but there are two small compilation issues for me.
e5b68e3
to
414920b
Compare
Compiles now for all of my platforms. But I noticed something that does not seem quite right:
|
Uh good catch! |
Yep, can confirm. Let's see what murdock thinks about it. |
There is still no test application so no compile test :( |
Whoops true 😄 The |
I now added a unit test for the module. |
I think the test should also cover that the cache eviction is working properly. The case of setting IPv6 for a domain but requesting IPv4 is already included, the mirrored case would also be nice to include. |
Not necessarily needed to be done in this PR and wrt to #16705 I admit that I have an agenda ;-P, but I see some overlap between this cache and |
b51ba34
to
48d4b17
Compare
Happy happy API change and another user of |
About the long unittests: Can you reproduce this locally? Maybe for some reason there is some spin- or deadlock? |
I don't see the timeout when I run the test locally. |
Mh but the tests get stuck for a while for me when I run it locally... |
TEST_ASSERT_EQUAL_INT(0, sock_dns_cache_query("example.comm", &addr_out, AF_INET6)); | ||
TEST_ASSERT_EQUAL_INT(0, sock_dns_cache_query("example.co", &addr_out, AF_INET6)); | ||
|
||
ztimer_sleep(ZTIMER_MSEC, 2000); |
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.
Do we really have to have 2 seconds here? Can't you mock the now value or timeout some how to enforce a timeout?
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.
Alternatively, for testing you could make the clock resolution of sock_dns_cache_add()
's ttl
configurable, and have it in milliseconds specifically for the tests.
Here's the full output from my local runs
It get's stuck in
|
:-/
|
@benpicco: for your local tests: did you run all the unittests or just the |
Uh good point, when I run all the tests I also see the hang. |
The sleep does not hang when I use |
Would still prefer a solution that does not slow down the unittests by 2 seconds, but won't block. |
I think 2s isn't so bad in the grand scheme of things. |
Contribution description
If a domain is used multiple times, RIOT will issue a new DNS query each time. This can add unwanted network overhead and latency, so caching DNS entries can be desirable.
If the cache is full, the first entry to expire will be evicted.
Testing procedure
The DNS cache is enabled with
Issues/PRs references