Skip to content

fix: retire Web mDNS without blocking session shutdown - #49

Merged
fython merged 1 commit into
mainfrom
codex/fix-web-mdns-async-lifecycle
Oct 24, 2026
Merged

fython merged 1 commit into
mainfrom
codex/fix-web-mdns-async-lifecycle

Conversation

@fython

@fython fython commented Oct 23, 2026

Copy link
Copy Markdown
Owner

从 Android 主线程停止 Web 服务或修改 mDNS 主机名时,原实现会持有 WebSession 锁等待 JmDNS 注册/注销,多个接口可能累计等待数秒。现在 mDNS 的注册、网络刷新和清理均由各自生命周期的工作线程串行处理,停止只发出失效信号并排队清理,媒体查询无需等待 mDNS 注销。

  • 每个 WebMdns 实例独占 responder、多播锁和工作线程;旧实例的慢清理不会占用新实例的线程或修改其状态。
  • 停止后跳过排队刷新;创建/注册期间完成的过期 responder 在原工作线程回收。多播锁保留到 responder 清理完成,沿用 fix: hold an independent multicast lock for Web mDNS #48 的独立锁管理。
  • WebSession 先解除对旧 mDNS 实例的引用,再异步退役。mDNS 生命周期回归测试扩充到 21 项,覆盖主线程停止、媒体查询、慢注册/注销、快速重启和网络切换。

验证:./gradlew :common:testDebugUnitTest :mobile:compileDebugKotlin 通过;common 共 397 个测试,零失败。可控慢注销测试在释放阻塞点前验证主线程停止、媒体查询和新实例发布均可完成,并检查旧资源最终只清理一次。

真机验证待执行:多网络接口下反复启停 Web 服务、修改主机名及切换 Wi-Fi,检查界面响应、媒体请求、mDNS 解析和多播锁最终释放。当前云环境未连接目标 Android 真机,尚未完成真实设备上的 ANR/切网验证。

Fixes #46

Keep registration, network refresh and responder cleanup on a worker owned by each WebMdns lifecycle. Close only invalidates the lifecycle and queues cleanup, so service stop and hostname changes never wait for JmDNS while holding the WebSession monitor.

Discard late responders and queued refreshes after retirement, keep multicast locks until cleanup finishes, and cover slow creation, registration, unregistration, network replacement and overlapping lifecycles with deterministic tests.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Failed ❌

View logs ↗
6229272 2026-10-23T16:13:30.460Z View logs ↗

@fython
fython merged commit a8fb1e1 into main Oct 24, 2026
4 of 7 checks passed
@fython
fython deleted the codex/fix-web-mdns-async-lifecycle branch October 24, 2026 07:16
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.

[P2] Web 服务停止同步注销 mDNS,阻塞主线程及 WebSession 锁

2 participants