Title: feat(net): cache async DNS resolutions to reuse across requests by jnuyens · Pull Request #189 · MicroPythonOS/MicroPythonOS · GitHub
Open Graph Title: feat(net): cache async DNS resolutions to reuse across requests by jnuyens · Pull Request #189 · MicroPythonOS/MicroPythonOS
X Title: feat(net): cache async DNS resolutions to reuse across requests by jnuyens · Pull Request #189 · MicroPythonOS/MicroPythonOS
Description: What async_dns.getaddrinfo_async now caches successful resolutions per (host, port, proto, socktype) with a 5-minute TTL, so repeated lookups for the same host reuse the result instead of spawning a resolver worker thread each time. Why getaddrinfo_async spawns a _thread worker per lookup (correctly, to keep the loop alive during blocking DNS). But the ESP32-S3 thread pool is small, so any workload that resolves the same host repeatedly can exhaust it, after which new lookups fail with OSError: can't create thread and downstream requests fail. This showed up in the wild on a Fri3d badge: streaming an album (a fetch per fragment) alongside a background app that constantly retried unreachable relays drained the pool, and both then hit can't create thread. The fetches and the retries were all re-resolving the same handful of hosts every time. Caching the resolution removes those redundant threads entirely, so retries and repeat downloads become pure-async. Details Cache check runs before the sys.platform == "linux" branch, so it applies on both desktop and ESP32 (and is exercised by the desktop tests). Only successful results are cached; failures re-resolve (so a transient error is not sticky). clear_dns_cache() is exposed for network changes / tests. 5-minute TTL keeps entries fresh enough to follow DNS changes. Tests tests/test_async_dns.py: setUp/tearDown clear the cache; two new tests verify a repeated lookup hits the cache (no re-resolve) and that a failed lookup is not cached. All pass on the desktop build (./tests/unittest.sh tests/test_async_dns.py). Follow-up to the off-loop DNS work in async_dns.
Open Graph Description: What async_dns.getaddrinfo_async now caches successful resolutions per (host, port, proto, socktype) with a 5-minute TTL, so repeated lookups for the same host reuse the result instead of spawning ...
X Description: What async_dns.getaddrinfo_async now caches successful resolutions per (host, port, proto, socktype) with a 5-minute TTL, so repeated lookups for the same host reuse the result instead of spawning ...
Opengraph URL: https://github.com/MicroPythonOS/MicroPythonOS/pull/189
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a7a074fd-8f88-88dd-c1f9-2990e9514f38 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D91A:171DD4:143C176:1AFA40F:6A52A8C9 |
| html-safe-nonce | d575f9ffd5798b6e777c140b76c94368caecce131fb30b0fb31031606906c5f6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTFBOjE3MURENDoxNDNDMTc2OjFBRkE0MEY6NkE1MkE4QzkiLCJ2aXNpdG9yX2lkIjoiMjA0ODIzNzE1MDY5OTk1MjA5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 7cc32587b0d69fad571110d76657abe72d7ef43d990575b2e3e5ecd014444c58 |
| hovercard-subject-tag | pull_request:4024756839 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/MicroPythonOS/MicroPythonOS/pull/189/files |
| twitter:image | https://avatars.githubusercontent.com/u/3696148?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/3696148?s=400&v=4 |
| og:image:alt | What async_dns.getaddrinfo_async now caches successful resolutions per (host, port, proto, socktype) with a 5-minute TTL, so repeated lookups for the same host reuse the result instead of spawning ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/MicroPythonOS/MicroPythonOS git https://github.com/MicroPythonOS/MicroPythonOS.git |
| octolytics-dimension-user_id | 213598128 |
| octolytics-dimension-user_login | MicroPythonOS |
| octolytics-dimension-repository_id | 975472483 |
| octolytics-dimension-repository_nwo | MicroPythonOS/MicroPythonOS |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 975472483 |
| octolytics-dimension-repository_network_root_nwo | MicroPythonOS/MicroPythonOS |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width