Repository navigation
[Bug]First file-lock acquisition can stall the event loop ~40 s #13852
OJuisPlease
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
中文
运行环境
origin/master@2e39e70496(0.2.2-rc.5),从构建产物启动:node apps/cli/lib/bin.js webhttp://127.0.0.1:3080/(WSL localhost 转发)web,装有少量插件;本次运行中浏览器对首屏资源返回304(已缓存)复现步骤
node apps/cli/lib/bin.js webdsh web: http://127.0.0.1:3080/?token=…实际表现
打印 URL 之后约 40 秒,浏览器发出的第一个静态请求才到达服务器(访问日志):
这段时间内宿主事件循环完全没有运行。宿主内每 100 ms 计时一次的监视器记录到一次停顿:
停顿期间发出的所有网关请求被同时压住,并在同一时刻一起返回:
出站的账号请求在停顿结束后才报
no-response/aborted: true,说明连中止定时器也无法运行。由于事件循环被占住,页面无法交互,服务器进程收到
Ctrl+C也要等到停顿结束才响应。期望表现
启动应在数秒内完成;URL 打印后应能立即响应首个页面请求;进程应在收到信号时及时响应。
CPU 采样证据
宿主进程的 CPU profile(跨度 449 秒)中,9.1% 的采样落在
node:internal/process/report#getReport,约 36 000 个采样 ≈ 40 秒。调用链:出错代码(官方代码,未被本地修改)
native/system/packages/entry/src/flock.ts的loadBinding():它能影响启动,有两个前提:
flock时才加载;而会话存储在获取写租约/投影锁时就会触发,此时 Web 服务器已经开始监听并打印了 URL。process.report.getReport()是同步生成完整诊断报告。本机上该调用耗时约 40 秒,其他机器上同样的代码只需毫秒级,所以症状表现为间歇性,容易被误判为网络或渲染问题。该问题来自官方代码:所报告的构建是定制分支,但上述文件与
origin/master逐字相同(修复前的提交执行git diff origin/master <pre-fix-commit> -- native/system/packages/entry/src/flock.ts输出为空),定制分支没有修改它。可能的修复方向
选择 libc 版本时不要生成报告:直接
requireglibc/system.node,当该模块不存在时回退到musl/system.node。这样第一次抢锁路径上就没有一个代价无上界的同步调用。English
Environment
origin/master@2e39e70496(0.2.2-rc.5), launched from built artifacts (node apps/cli/lib/bin.js web)http://127.0.0.1:3080/(WSL localhost forwarding)webwith a few installed plugins; first-screen assets were served as304(already cached) in this runSteps to reproduce
node apps/cli/lib/bin.js webdsh web: http://127.0.0.1:3080/?token=…Actual behaviour
The first static request from the browser reaches the server only about 40 s after the URL is printed:
For those ~40 s the host does not run its event loop at all; a 100 ms tick monitor inside the host records one stall:
Every gateway request issued before the stall is held for the same duration and they all complete at once:
Outbound account requests surface as
no-response/aborted: trueonly after the stall, so even their abort timers could not run.With the loop blocked, the UI cannot be interacted with, and
Ctrl+Con the server process does not take effect until the stall ends.Expected behaviour
Startup should complete in the low seconds; the first page request should be answered as soon as the URL is printed; the process should react to signals.
CPU profile evidence
In a host CPU profile (449 s span), 9.1% of samples sit inside
node:internal/process/report#getReport— about 36 000 samples ≈ 40 s. Call chain:Code at fault (upstream, unmodified locally)
native/system/packages/entry/src/flock.ts,loadBinding():Two facts put this on the startup path:
flockacquisition, which the session store performs when it acquires its write lease / projection lock — after the Web server has already started listening and printed its URL.process.report.getReport()builds a full diagnostic report synchronously. On this host it takes ~40 s; the same code costs milliseconds elsewhere, which is why the symptom is intermittent and has been misread as a network or rendering problem.This is official code: the reporting build is a fork, but the file above is byte-identical to
origin/master(git diff origin/master <pre-fix-commit> -- native/system/packages/entry/src/flock.tsis empty), and the fork does not modify it.Possible direction
Pick the libc without generating a report:
requiretheglibc/system.nodebuild and fall back tomusl/system.nodewhen that module is absent, so the first lock acquisition no longer contains a synchronous call with unbounded cost.All reactions