Title: feat(net): off-loop DNS resolution so connecting doesn't freeze the event loop / UI by jnuyens · Pull Request #177 · MicroPythonOS/MicroPythonOS · GitHub
Open Graph Title: feat(net): off-loop DNS resolution so connecting doesn't freeze the event loop / UI by jnuyens · Pull Request #177 · MicroPythonOS/MicroPythonOS
X Title: feat(net): off-loop DNS resolution so connecting doesn't freeze the event loop / UI by jnuyens · Pull Request #177 · MicroPythonOS/MicroPythonOS
Description: Summary Opening a network connection briefly freezes the whole UI during the DNS lookup (worst for unreachable / non-existent hosts). Easy to reproduce by connecting to a random non-existent host (e.g. akhegfkfkqhskfhesbfkwlmd.com). Root cause asyncio.open_connection() calls socket.getaddrinfo() synchronously before its first yield (extmod/asyncio/stream.py -- the upstream source even has a # TODO this is blocking! there). On ESP32-S3 that blocking DNS call runs on the asyncio event-loop thread, which is also the thread that drives the LVGL UI via micropython.schedule(). So while getaddrinfo waits, the scheduler can't run, LVGL never ticks, and the UI is frozen for the full DNS duration. This is not an unfixable ESP-IDF limitation: lwIP DNS is async internally, and ESP32's getaddrinfo releases the GIL while it waits (ports/esp32/modsocket.c), so another _thread keeps running during the lookup. The fix is entirely at the Python layer. Fix New mpos/net/async_dns.getaddrinfo_async(): resolves DNS in a _thread worker (same pattern as audiomanager.py / wifi_service.py) and await-polls via TaskManager.sleep_ms(), so the event loop / UI keep ticking while DNS resolves. It does not import asyncio (honors the "only TaskManager imports asyncio" rule). aiohttp now resolves the host off-loop, then connects to the resolved IP with server_hostname=host so TLS SNI and cert validation still use the real hostname. DNS + connect run together under the existing request timeout. Testing tests/test_async_dns.py (network-free, deterministic): proves the loop keeps ticking while a 150 ms-blocking lookup runs, and that worker exceptions propagate. Regression: existing aiohttp-path tests still pass. Live-verified on the desktop simulator against a dead host: old path = 0 UI ticks during the lookup; new path = loop kept ticking the whole time. (On-device the difference is multi-second.) No new dependencies; ASCII-only; behavior unchanged for normal hosts.
Open Graph Description: Summary Opening a network connection briefly freezes the whole UI during the DNS lookup (worst for unreachable / non-existent hosts). Easy to reproduce by connecting to a random non-existent host (...
X Description: Summary Opening a network connection briefly freezes the whole UI during the DNS lookup (worst for unreachable / non-existent hosts). Easy to reproduce by connecting to a random non-existent host (...
Opengraph URL: https://github.com/MicroPythonOS/MicroPythonOS/pull/177
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:f4c69eb1-6b33-999c-1ec6-c47691315f6f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D606:1802DE:49C77D:695179:6A50FAC3 |
| html-safe-nonce | d4028a8dfc631ee2e664e09a41eaf7f2d6dc977ffb4fe41626136f77ff9145dd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjA2OjE4MDJERTo0OUM3N0Q6Njk1MTc5OjZBNTBGQUMzIiwidmlzaXRvcl9pZCI6IjUyODYyNDExMTExMzU4MTIyOTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d431b0d74763447297714f0fdb22ef57577528b263ca399555d0d81c00d828a8 |
| hovercard-subject-tag | pull_request:3950603572 |
| 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/177/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 | Summary Opening a network connection briefly freezes the whole UI during the DNS lookup (worst for unreachable / non-existent hosts). Easy to reproduce by connecting to a random non-existent host (... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5266e58c17a510c403505cc811606465e90a881d2007ee7df1c4800d5c659838 |
| 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 | 8d836581d020676cc0ef4a83cd2fe17e4af02c3d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width