Repository navigation
fix(build): Remotion 渲染服务只监听本机回环地址 - #143
Merged
Merged
Conversation
JunieXD
marked this pull request as ready for review
October 12, 2026 03:24
Member
|
这个修复方向认可,渲染服务和端口探测都限制在本机回环地址很有必要。复核时发现一个需要先补齐的小问题:
我们做了一个隔离模拟:绑定和关闭监听成功后,让连接既不触发 麻烦补一下:
补齐这个点后就可以继续推进合并。谢谢! |
Contributor
Author
|
已补上,见 12fb733(同时合并了 main):
在 mac 上用打包应用换上新补丁复测:Studio 视频渲染正常,只监听 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Studio 渲染视频时,Remotion 会在本机起一个 HTTP 服务,给浏览器提供打包好的页面,以及视频帧代理
/proxy。这个服务监听所有网卡(::或0.0.0.0),找空闲端口时也会在所有网卡上短暂监听。这带来两个问题:public下的素材(配音、图片、背景音乐),还能通过/proxy让本机按它给的地址发起请求。在 main 上实测:/proxy?src=http://127.0.0.1:<端口>/...,一个只监听本机的服务收到了请求。node.exe弹出“是否允许公共网络和专用网络访问此应用”。不处理也不影响渲染;点“允许”则会永久放行这个程序的入站连接。Remotion 没有设置监听地址的选项,上游最新代码也一样。所以和
patch-session-search-runtime.mjs一样,在组装时给复制出来的 Runtime 打补丁。改动
补丁(
scripts/patch-remotion-renderer-runtime.mjs):修改@remotion/renderer4.0.520 的两个文件。修改前按 SHA-256 校验输入,修改前后的哈希记入assembly.json的runtimePatches。dist/port-config.js:服务只监听127.0.0.1,找端口时只在本机回环地址(::1、127.0.0.1)上试。dist/get-port.js:试绑定成功后,再连一下这个地址,有程序应答就换下一个端口。别的程序占着::或0.0.0.0的同一端口时(不指定地址的 Node 服务默认就是这样),只绑回环地址仍能成功,但页面里的localhost会先连::1,落到那个程序上。Remotion 原本靠在所有网卡上试绑定来发现这种冲突,现在改用连接来发现。连接 1 秒内既没连上也没被拒时,同样判为已占用、换下一个端口,并关闭这次连接,端口选择不会一直等下去。本机回环地址的连接被拒一般在十几毫秒内返回。页面地址仍是
http://localhost:<端口>。<OffthreadVideo>取帧的地址在 Remotion 里写死为localhost,也不受影响:浏览器先试::1,被拒后立即改连127.0.0.1。只改桌面产品。Local Web 和直接使用 npm 包的部署仍是 Remotion 原来的行为。Remotion 升级时,如果上游已有等价修复,删掉这个补丁。
测试:
validate-pinned-dsh-source新增scripts/test/remotion-renderer-runtime.test.mjs,检查组装好的产品:::或0.0.0.0上的端口时,这个端口判为已占用;localhost能访问,通过本机各网卡地址都连不上;net模块)。不带超时的版本过不了这项测试。未打补丁的渲染器和只改监听地址、不加连接检查的版本,都过不了这项测试。
本 PR 和 #141 都改了
assemble-pinned-dsh-source-product.mjs中runtimePatches那一行,也都改了源码回执。后合入的一个需要合并这一行,并刷新回执。验证:macOS 27.0.1 arm64
本机构建,流水线自带的检查全部通过。DMG 挂载校验没有执行:构建工作区在外接盘上,而 macOS 不允许把镜像挂载到
/Volumes下的目录,main 对照包同样如此。用打包后的应用渲染 Studio 视频(H.264 + AAC,6 秒):*:3000127.0.0.1:3000/proxy让本机发请求::、::1、0.0.0.0上占着 3000 端口时,渲染改用 3001,视频正常。<OffthreadVideo>播放本地视频的工程(视频帧经localhost上的/proxy取得)渲染正常,第 2 秒的画面与原视频一致。<OffthreadVideo>工程同样正常,也只监听127.0.0.1。127.0.0.1:3000,局域网地址连接被拒;3000 被0.0.0.0占用时改用 3001。验证:Windows 11 ARM64 虚拟机(x64 仿真)
把 0.4.2 正式版 Windows 包解压成两份:一份不动,一份用本 PR 的补丁脚本打补丁。两份各渲染一次 Studio 视频:
[::]:3000、0.0.0.0:3000127.0.0.1:3000node.exe测试:只在::上监听一瞬间就关(Remotion 找端口时就是这样),也会弹窗;只监听127.0.0.1或::1不会。[::]:3000时,渲染改用 3001;<OffthreadVideo>工程渲染正常,画面与原视频一致;<OffthreadVideo>渲染结束后,一个 chrome.exe 网络服务子进程卡在退出状态,锁住了测试目录。原版和打补丁的各重复渲染 3 次,都没有再现。未测: