Repository navigation
VLESS Multiplex (mux.cool): MutexWriter passes Interrupt and Close through - #7355
Medium1992 wants to merge 1 commit into
Conversation
…rough Since 5745dea the workers' common.Interrupt(link.Writer) reaches a MutexWriter, which embeds only buf.Writer, and does nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
|
|
Update:并不会触发 |
|
看了下代码,ServerWorker/ClientWorker 的 monitor() 会调用 common.Interrupt(m.link.Writer) |
|
VLESS 服务端 DispatchLink() 并不会触发问题, func (s *Server) DispatchLink(ctx context.Context, dest net.Destination, link *transport.Link) error {
if dest.Address != muxCoolAddress {
return s.dispatcher.DispatchLink(ctx, dest, link)
}
worker, err := NewServerWorker(ctx, s.dispatcher, link)
if err != nil {
return err
}
select {
case <-ctx.Done():
case <-worker.done.Wait():
}
return nil
}这里直接 return 回 VLESS 入站,结束, |
|
客户端的是 Mux 生成了一对 pipe 给 VLESS 出站,若由 Mux 发起关闭,虽然关不掉 upLinkWriter 了但能关掉 downlinkReader func (f *DialingWorkerFactory) Create() (*ClientWorker, error) {
opts := []pipe.Option{pipe.WithSizeLimit(64 * 1024)}
uplinkReader, upLinkWriter := pipe.New(opts...)
downlinkReader, downlinkWriter := pipe.New(opts...)
c, err := NewClientWorker(transport.Link{
Reader: downlinkReader,
Writer: upLinkWriter,
}, f.Strategy)
if err != nil {
return nil, err
}
go func(p proxy.Outbound, d internet.Dialer, c common.Closable) {
outbounds := []*session.Outbound{{
Target: net.TCPDestination(muxCoolAddress, muxCoolPort),
}}
ctx := session.ContextWithOutbounds(context.Background(), outbounds)
ctx, cancel := context.WithCancel(ctx)
if errP := p.Process(ctx, &transport.Link{Reader: uplinkReader, Writer: downlinkWriter}, d); errP != nil {
errC := errors.Cause(errP)
if !(goerrors.Is(errC, io.EOF) || goerrors.Is(errC, io.ErrClosedPipe) || goerrors.Is(errC, context.Canceled)) {
errors.LogInfoInner(ctx, errP, "failed to handler mux client connection")
}
}
common.Must(c.Close())
cancel()
}(f.Proxy, f.Dialer, c.done)
return c, nil
}
Update:后半句可能不对 |
|
Server side: agreed, closing the inbound connection unblocks it. Client side does leak, though. If the connection drops during an upload, the session goroutines are blocked writing into the full 64 KiB uplink pipe. Nobody reads testtype dropOutbound chan struct{}
func (d dropOutbound) Process(context.Context, *transport.Link, internet.Dialer) error {
<-d // never reads the uplink, then the connection "drops"
return io.ErrUnexpectedEOF
}
func TestClientWorkerDropDuringUpload(t *testing.T) {
drop := make(dropOutbound)
w, _ := (&mux.DialingWorkerFactory{Proxy: drop, Strategy: mux.ClientStrategy{MaxConcurrency: 8, MaxConnection: 8}}).Create()
ctx := session.ContextWithOutbounds(context.Background(), []*session.Outbound{{Target: net.TCPDestination(net.DomainAddress("example.com"), 80)}})
r, wr := pipe.New(pipe.WithoutSizeLimit())
_, out := pipe.New(pipe.WithoutSizeLimit())
for i := 0; i < 32; i++ { // 256 KiB, more than the 64 KiB uplink pipe
b := buf.New()
b.Extend(buf.Size)
wr.WriteMultiBuffer(buf.MultiBuffer{b})
}
w.Dispatch(ctx, &transport.Link{Reader: r, Writer: out})
time.Sleep(500 * time.Millisecond)
close(drop)
<-w.WaitClosed()
time.Sleep(time.Second)
stack := make([]byte, 1<<20)
if strings.Contains(string(stack[:runtime.Stack(stack, true)]), "mux.fetchInput") {
t.Fatal("session goroutine still blocked on the uplink after the worker closed")
}
} |
|
客户端大概是这样:Mux 内发起关闭 downlinkReader 导致 VLESS 出站双向 copy 结束返回到 Update:逻辑或许是 VLESS 出站无法往回写 downlinkWriter -> 底层连接关闭 -> VLESS 出站无法往外写 -> 双向 copy 结束 大概只有 Mux 内 idle timeout 是这条路,如果是 VLESS 客户端到服务端的连接断掉了的情况,这个 ClientWorker 也肯定没了 |
|
The test is the dropped-connection path: |
func (m *ClientWorker) Dispatch(ctx context.Context, link *transport.Link) bool {
if m.IsFull() {
return false
}
sm := m.sessionManager
s := sm.Allocate(&m.strategy, link.Reader, link.Writer)
if s == nil {
return false
}
go fetchInput(ctx, s, m.link.Writer)
if _, ok := link.Reader.(*pipe.Reader); !ok {
select {
case <-ctx.Done():
case <-s.done.Wait():
}
}
return true
}
|
|
Yes, inside |
|
不过触发条件是它正好处于写满等位置、但 VLESS 出站不再从 Mux 客户端读取的状态,不一定触发,因为 VLESS 客户端到服务端的连接断掉后,应用程序到 VLESS 客户端的连接会关掉,Mux 内 buf.Copy() 本身从应用程序读取都会失败,就不会等待写
无论如何,这个 PR 肯定会合并, |
|
总之 v2 这架构读起来还是太耗费脑细胞了,正好要重整 Mux #4231 改为由 VLESS 出站调用吧,其它出站不管了 @Fangliding |
|
哎呀 那个改动不该合的 我之前就关掉一个 这段时间忙一点没怎么看PR就炸了 |
|
这个 PR 修的问题是很小的问题,只是这个 PR 正好提醒了要把 Mux 客户端模块移到 VLESS 出站内调用, |
|
唉算了我来吧 |
|
|
…iplex` in VLESS/VMess outbound (#7364) #6748 (comment) #7240 (comment) #4231 (comment) #7355 (comment) #7359 (comment) #7364 (comment) #7364 (comment) #7364 (comment) #4231 (comment) #7364 (comment) #7364 (comment) #7364 (comment) --------- Co-authored-by: Codex <[email protected]> Co-authored-by: RPRX <[email protected]>
… `settings.multiplex` in VLESS/VMess outbound (#7364) #6748 (comment) #7240 (comment) #4231 (comment) #7355 (comment) #7359 (comment) #7364 (comment) #7364 (comment) #7364 (comment) #4231 (comment) #7364 (comment) #7364 (comment) #7364 (comment) --------- Co-authored-by: Codex <[email protected]> Co-authored-by: RPRX <[email protected]>
… only uses `settings.multiplex` in VLESS/VMess outbound (#7364) #6748 (comment) #7240 (comment) #4231 (comment) #7355 (comment) #7359 (comment) #7364 (comment) #7364 (comment) #7364 (comment) #4231 (comment) #7364 (comment) #7364 (comment) #7364 (comment) --------- Co-authored-by: Codex <[email protected]> Co-authored-by: RPRX <[email protected]>
Since 5745dea
common.Interrupt(link.Writer)in the mux client and server workers hits aMutexWriter, which embeds onlybuf.Writer, so it does nothing: a closed worker leaves its link open, and a write stuck on a peer that stopped reading never returns.MutexWriternow passesInterruptandCloseto the writer inside, without the lock; the tests fail on v26.11.9 and pass with this.🤖 Generated with Claude Code