@@ -2,6 +2,7 @@ package mux
22
33import (
44 "context"
5+ goerrors "errors"
56 "io"
67 "sync"
78 "time"
@@ -154,8 +155,11 @@ func (f *DialingWorkerFactory) Create() (*ClientWorker, error) {
154155 ctx := session .ContextWithOutbounds (context .Background (), outbounds )
155156 ctx , cancel := context .WithCancel (ctx )
156157
157- if err := p .Process (ctx , & transport.Link {Reader : uplinkReader , Writer : downlinkWriter }, d ); err != nil {
158- errors .LogInfoInner (ctx , err , "failed to handler mux client connection" )
158+ if errP := p .Process (ctx , & transport.Link {Reader : uplinkReader , Writer : downlinkWriter }, d ); errP != nil {
159+ errC := errors .Cause (errP )
160+ if ! (goerrors .Is (errC , io .EOF ) || goerrors .Is (errC , io .ErrClosedPipe ) || goerrors .Is (errC , context .Canceled )) {
161+ errors .LogInfoInner (ctx , errP , "failed to handler mux client connection" )
162+ }
159163 }
160164 common .Must (c .Close ())
161165 cancel ()
@@ -222,7 +226,7 @@ func (m *ClientWorker) monitor() {
222226 select {
223227 case <- m .done .Wait ():
224228 m .sessionManager .Close ()
225- common .Close (m .link .Writer )
229+ common .Interrupt (m .link .Writer )
226230 common .Interrupt (m .link .Reader )
227231 return
228232 case <- m .timer .C :
@@ -247,7 +251,7 @@ func writeFirstPayload(reader buf.Reader, writer *Writer) error {
247251 return nil
248252}
249253
250- func fetchInput (ctx context.Context , s * Session , output buf.Writer ) {
254+ func fetchInput (ctx context.Context , s * Session , output buf.Writer , timer * time. Ticker ) {
251255 outbounds := session .OutboundsFromContext (ctx )
252256 ob := outbounds [len (outbounds )- 1 ]
253257 transferType := protocol .TransferTypeStream
@@ -258,6 +262,7 @@ func fetchInput(ctx context.Context, s *Session, output buf.Writer) {
258262 writer := NewWriter (s .ID , ob .Target , output , transferType , xudp .GetGlobalID (ctx ))
259263 defer s .Close (false )
260264 defer writer .Close ()
265+ defer timer .Reset (time .Second * 16 )
261266
262267 errors .LogInfo (ctx , "dispatching request to " , ob .Target )
263268 if err := writeFirstPayload (s .input , writer ); err != nil {
@@ -308,9 +313,9 @@ func (m *ClientWorker) Dispatch(ctx context.Context, link *transport.Link) bool
308313 s .input = link .Reader
309314 s .output = link .Writer
310315 if _ , ok := link .Reader .(* pipe.Reader ); ok {
311- go fetchInput (ctx , s , m .link .Writer )
316+ go fetchInput (ctx , s , m .link .Writer , m . timer )
312317 } else {
313- fetchInput (ctx , s , m .link .Writer )
318+ fetchInput (ctx , s , m .link .Writer , m . timer )
314319 }
315320 return true
316321}
0 commit comments