-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed the issue that the TCP connection was interrupted when setting a proxy #9708
Fixed the issue that the TCP connection was interrupted when setting a proxy #9708
Conversation
Your PR was set to target |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
30b75a4
to
7452801
Compare
8570b75
to
78ccf48
Compare
app/src/util/serviceWorker.ts
Outdated
if (!("serviceWorker" in navigator) || typeof (navigator.serviceWorker) === "undefined" || | ||
!("caches" in window) || !("fetch" in window)) { | ||
return; | ||
export const registerServiceWorker = async (scriptURL: string, scope = "/", workerType: WorkerType = "module") => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
和 proxy 没有关系的代码麻烦不要提交。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
和 proxy 没有关系的代码麻烦不要提交。
这里是为了避免加载 service-worker 时对现有请求造成不可预期的影响,是相关的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个只有在浏览器端和移动端使用,和 electron 的 setProxy 无关。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个只有在浏览器端和移动端使用,和 electron 的 setProxy 无关。
我在使用中发现在 electron 中使用 <iframe>
或 <webview>
标签访问 /stage/build/desktop/
与 /stage/build/mobile/
也会触发 service-worker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
registerServiceWorker 这个好像还是你 PR 的,是不是这些情况排查漏了。这个问题应该从源头上改进,而不是对错误进行兼容。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
registerServiceWorker 这个好像还是你 PR 的,是不是这些情况排查漏了。这个问题应该从源头上改进,而不是对错误进行兼容。
原有实现暂时也未出现问题, 这里的改进是为了消除不确定性
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前的 registerServiceWorker 为什么要在 electron 中运行?感觉是没有必要的。不是出现问题才是有 bug。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是 registerServiceWorker
要在 electron 中运行, 而是无法完全阻止 registerServiceWorker
在 electron 中运行, 因为 <iframe>
与 <webview>
的上下文可能是完全隔离的
不过我刚刚有一个想法, 在 electron 环境中检测到 service-worker 后可以自动注销该 worker, 我先去测试一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Vanessa219
提交了一个解决方案: 在启动时从桌面端与移动端 App 中注销当前存在的 service-worker
详情请参考 36bad6c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
能不能不要搅和在这个 issue 里面呀 😭
目前有 2 个问题需要先确认一下:
|
应该是需要的, 不然可能在遇到 TCP 长连接时会引入更加复杂的问题
electron 的 |
closeAllConnections 把长链接断开了,好像没有机制重新再次建立长链接?如果不断的话会有什么问题? 需要代理 kernel 请求的场景是? |
用户发起请求时可以重新建立长连接
可能会出现切换代理后用户的请求复用切换代理前的长连接, 与用户切换代理的期望不符
用户在如下场景中都有绕过代理的需求
|
代理主要用途为外网非本地的,无法保证外网的程序都有这个机制。不行的话,切换的时候就直接刷界面吧。 本机访问不太建议走代理,首先没有必要,其次会减慢速度。
|
electron 的代理都是 web 服务使用, HTTP 可以保证都有这个机制, 无需刷新界面
这里可能理解有误, 之前提到的 |
websocket 也可以? 没有误解,一开始我问的是,而不是
|
我这里切换代理前后都是正常连接的
这个场景不多 |
e6fedde
to
deb2801
Compare
deb2801
to
36bad6c
Compare
非常感谢你前期的调研和贡献。基于你前期的调研,今早和 D 研究测试了一下,现在的 PR 在某些场景下还是有问题,因此只能关闭这个 PR,非常抱歉。 |
更新默认session的proxy,好像不刷新也能直接用吧? |
长链接不会断开,使用不了更新后的。 |
setProxy
函数, 避免在中断所有 TCP 连接时中断部分向内核发出的请求Call the
setProxy
function synchronously when there are no other requests to avoid interrupting some requests to the kernel when all TCP connections are interruptedTESTED
REF: https://ld246.com/article/1700548414564