-
Notifications
You must be signed in to change notification settings - Fork 4k
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
修复mux子连接无法正常断开的问题 #1417
修复mux子连接无法正常断开的问题 #1417
Conversation
…ing an End status.
תודה אתה
----------------------------------------
*From: *renahita6 ***@***.***>
*To: *XTLS/Xray-core ***@***.***>
*CC: *Subscribed ***@***.***>
*Date: *Dec 9, 2022 03:59:32
*Subject: *[XTLS/Xray-core] 修复mux子连接无法正常断开的问题 (PR #1417)
ray系的mux一直有一个老毛病,取消下载文件后流量还会继续跑,比如#232[#232]。
排查后发现问题出在*commom/mux/server.go*文件下的*handleStatusEnd*函数。
具体而言,*mux*客户端向服务端发送*End*状态请求结束对应的*mux.Session*时,服务端接受到该请求,并最终进入*handleStatusEnd*函数:
*func (w *ServerWorker) handleStatusEnd(meta *FrameMetadata, reader
*buf.BufferedReader) error {
if s, found := w.sessionManager.Get(meta.SessionID); found {
...
s.Close()
}
...
return nil
}
*
上述*if*语句中的*s.Close*函数:
*func (s *Session) Close() error {
common.Close(s.output)
common.Close(s.input)
s.parent.Remove(s.ID)
return nil
}
*
分别调用*s.input*和*s.output*的*Close*方法,然后将该*session*的*ID*从*sessionmanager*中移除。
问题出现在,*s.input*是一个*pipe.Reader*,在xray中*pipe.Reader*没有实现*Close*方法,导致子连接无法正常断开,远程服务器会持续通过该*pipe.Reader*传输数据。
解决方法很简单,在*s.Close()*前手动中止*pipe.Reader*即可:
*func (w *ServerWorker) handleStatusEnd(meta *FrameMetadata, reader
*buf.BufferedReader) error {
if s, found := w.sessionManager.Get(meta.SessionID); found {
...
common.Interrupt(s.input)
s.Close()
}
...
return nil
}
*
相应的,*commom/mux/client.go*文件下的*handleStatusEnd*函数也需要做出对应的修改。
----------------------------------------
*You can view, comment on, or merge this pull request online at:*
#1417
*Commit Summary*
* >
3ee99d9[3ee99d9]
Fixed a bug that mux.Session could not be properly closed when receiving
an End status.
*File Changes*
(2 files[https://github.com/XTLS/Xray-core/pull/1417/files])
* > *M*
common/mux/client.go[https://github.com/XTLS/Xray-core/pull/1417/files#diff-f4d27b2f8ba74472b3bb4a536eb3fc4f88693885eea6b8151ac25d534cc0d914]
(1)
* > *M*
common/mux/server.go[https://github.com/XTLS/Xray-core/pull/1417/files#diff-434091d781b682a4e6e760ee3554cd77aa3e8efccaaf2050ab1ff8661903e8a5]
(1)
*Patch Links:*
* > https://github.com/XTLS/Xray-core/pull/1417.patch
* > https://github.com/XTLS/Xray-core/pull/1417.diff
…
—
Reply to this email directly, view it on
GitHub[#1417], or
unsubscribe[https://github.com/notifications/unsubscribe-auth/AKGBAYFBQ47PBN4B7HHAYRLWMKVCFANCNFSM6AAAAAASY4EKNI].
You are receiving this because you are subscribed to this
thread.[Tracking
image][https://github.com/notifications/beacon/AKGBAYGG7JOOJY7SZEWQ3ILWMKVCFA5CNFSM6AAAAAASY4EKNKWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHFREK2CM.gif]Message
ID: ***@***.***>
|
Now the code could reduce some elapse time, but still have some
remaining, especially for data up.
…----------------------------------------
*From: *Nanyu ***@***.***>
*To: *XTLS/Xray-core ***@***.***>
*CC: *Nanyu ***@***.***>; Your activity
***@***.***>
*Date: *Dec 9, 2022 04:48:27
*Subject: *Re: [XTLS/Xray-core] 修复mux子连接无法正常断开的问题 (PR #1417)
תודה אתה
----------------------------------------
*From: *renahita6 ***@***.***>
*To: *XTLS/Xray-core ***@***.***>
*CC: *Subscribed ***@***.***>
*Date: *Dec 9, 2022 03:59:32
*Subject: *[XTLS/Xray-core] 修复mux子连接无法正常断开的问题 (PR #1417)
>
>
> ray系的mux一直有一个老毛病,取消下载文件后流量还会继续跑,比如#232[#232]。
> 排查后发现问题出在*commom/mux/server.go*文件下的*handleStatusEnd*函数。
>
>
> 具体而言,*mux*客户端向服务端发送*End*状态请求结束对应的*mux.Session*时,服务端接受到该请求,并最终进入*handleStatusEnd*函数:
>
> *func (w *ServerWorker) handleStatusEnd(meta *FrameMetadata, reader
> *buf.BufferedReader) error {
> if s, found := w.sessionManager.Get(meta.SessionID); found {
> ...
> s.Close()
> }
> ...
> return nil
> }
> *
> 上述*if*语句中的*s.Close*函数:
>
> *func (s *Session) Close() error {
> common.Close(s.output)
> common.Close(s.input)
> s.parent.Remove(s.ID)
> return nil
> }
> *
>
>
> 分别调用*s.input*和*s.output*的*Close*方法,然后将该*session*的*ID*从*sessionmanager*中移除。
>
>
> 问题出现在,*s.input*是一个*pipe.Reader*,在xray中*pipe.Reader*没有实现*Close*方法,导致子连接无法正常断开,远程服务器会持续通过该*pipe.Reader*传输数据。
> 解决方法很简单,在*s.Close()*前手动中止*pipe.Reader*即可:
>
> *func (w *ServerWorker) handleStatusEnd(meta *FrameMetadata, reader
> *buf.BufferedReader) error {
> if s, found := w.sessionManager.Get(meta.SessionID); found {
> ...
> common.Interrupt(s.input)
> s.Close()
> }
> ...
> return nil
> }
> *
> 相应的,*commom/mux/client.go*文件下的*handleStatusEnd*函数也需要做出对应的修改。
>
> ----------------------------------------
>
> *You can view, comment on, or merge this pull request online at:*
>
> #1417
>
>
> *Commit Summary*
>
* >
3ee99d9[3ee99d9]
Fixed a bug that mux.Session could not be properly closed when
receiving
an End status.
>
> *File Changes*
>
> (2 files[https://github.com/XTLS/Xray-core/pull/1417/files])
>
* > *M*
common/mux/client.go[https://github.com/XTLS/Xray-core/pull/1417/files#diff-f4d27b2f8ba74472b3bb4a536eb3fc4f88693885eea6b8151ac25d534cc0d914]
(1)
* > *M*
common/mux/server.go[https://github.com/XTLS/Xray-core/pull/1417/files#diff-434091d781b682a4e6e760ee3554cd77aa3e8efccaaf2050ab1ff8661903e8a5]
(1)
>
> *Patch Links:*
>
* > https://github.com/XTLS/Xray-core/pull/1417.patch
* > https://github.com/XTLS/Xray-core/pull/1417.diff
>
> —
> Reply to this email directly, view it on
> GitHub[#1417], or
>
> unsubscribe[https://github.com/notifications/unsubscribe-auth/AKGBAYFBQ47PBN4B7HHAYRLWMKVCFANCNFSM6AAAAAASY4EKNI].
> You are receiving this because you are subscribed to this
> thread.[Tracking
>
> image][https://github.com/notifications/beacon/AKGBAYGG7JOOJY7SZEWQ3ILWMKVCFA5CNFSM6AAAAAASY4EKNKWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHFREK2CM.gif]Message
> ID: ***@***.***>
>
—
Reply to this email directly, view it on
GitHub[#1417 (comment)],
or
unsubscribe[https://github.com/notifications/unsubscribe-auth/AKGBAYHCBGTJAQYQ2JK5XM3WMK2ZVANCNFSM6AAAAAASY4EKNI].
You are receiving this because you are subscribed to this
thread.[Tracking
image][https://github.com/notifications/beacon/AKGBAYE6LFEDOO6CHBSA6ITWMK2ZVA5CNFSM6AAAAAASY4EKNKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSQDFYHK.gif]Message
ID: ***@***.***>
|
Thanks for your comment! I have noticed that, but even with "mux: false" there still remain traffic elapsing when uploading. It seems that the reason behind download and upload is different. I am trying to figure it out. But I think this pr can deal with the download situation at least. |
感谢大佬pr!困扰了几代大佬的 MUX 传统艺能就这么给修复了?太强了
那么是否应该让 pipe.Reader 实现 Close 呢?
|
这个问题在#285中讨论过了,貌似会引入新的问题。 (btw我不是大佬,你才是大佬) |
@renahita6 嗯 回溯了一下历史讨论然后回到代码 发现了一些有趣的地方
现在问题是 除了你加的 handleStatusEnd 之外 mux 包里的其它地方需要不需要? |
这个问题我也思考过,貌似在 |
感谢大佬 先合了 准备发一版让大家测 :) |
大佬,对于mux的阻塞问题,是否有方法解决 |
优雅!特别优雅!大佬给fly那边也提个pr吧。 |
agreed. for example: // Close implements common.Closeable.
func (r *Reader) Close() {
r.pipe.Close()
} Xray-core/transport/pipe/reader.go Lines 9 to 27 in 15999e5
|
The actual behavior after modifying code in the way don't repair upload flow persistent for some seconds, and also make download flow delay more amount than merged code do.
Feb 10, 2023 08:04:50 rurirei ***@***.***>:
… 感谢大佬pr!困扰了几代大佬的 MUX 传统艺能就这么给修复了?太强了 有个问题,您提到
在xray中pipe.Reader没有实现Close方法,导致子连接无法正常断开
那么是否应该让 pipe.Reader 实现 Close 呢?
*func (r *Reader) Close() error {
return r.pipe.Close()
}
*
agreed.
—
Reply to this email directly, view it on GitHub[#1417 (comment)], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AKGBAYG5FUMYZBXPYKLTYZ3WWWA2DANCNFSM6AAAAAASY4EKNI].
You are receiving this because you commented.[Tracking image][https://github.com/notifications/beacon/AKGBAYESOZHGNWBKC4TXMMTWWWA2DA5CNFSM6AAAAAASY4EKNKWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSU57CAK.gif]
|
(And again. We don't write golang code, so maybe can't give help.)
|
try #1638 |
Modify code in server and client according to pr. ( Have checked code again, and timestamp of generated compilied file) |
could you try github actions arti https://github.com/XTLS/Xray-core/actions/runs/4141584865/jobs/7161323006 |
Sorry, code doesn't do its duty. |
(Download time elapse excess about two seconds, but upload will take for five) |
ray系的mux一直有一个老毛病,取消下载文件后流量还会继续跑,比如#232。
排查后发现问题出在
commom/mux/server.go
文件下的handleStatusEnd
函数。具体而言,
mux
客户端向服务端发送End
状态请求结束对应的mux.Session
时,服务端接受到该请求,并最终进入handleStatusEnd
函数:上述
if
语句中的s.Close
函数:分别调用
s.input
和s.output
的Close
方法,然后将该session
的ID
从sessionmanager
中移除。问题出现在,
s.input
是一个pipe.Reader
,在xray中pipe.Reader
没有实现Close
方法,导致子连接无法正常断开,远程服务器会持续通过该pipe.Reader
传输数据。解决方法很简单,在
s.Close()
前手动中止pipe.Reader
即可:相应的,
commom/mux/client.go
文件下的handleStatusEnd
函数也需要做出对应的修改。