Skip to content

Commit

Permalink
Fix vmess mux leak
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Dec 30, 2024
1 parent 8b806fd commit 7a74cdb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
)

func HandleMuxConnection(ctx context.Context, conn net.Conn, source M.Socksaddr, handler Handler) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
session := &serverSession{
ctx: ctx,
source: source,
Expand All @@ -29,12 +31,10 @@ func HandleMuxConnection(ctx context.Context, conn net.Conn, source M.Socksaddr,
streams: make(map[uint16]*serverStream),
writer: std_bufio.NewWriter(conn),
}
if ctx.Done() != nil {
go func() {
<-ctx.Done()
session.cleanup(ctx.Err())
}()
}
go func() {
<-ctx.Done()
session.cleanup(ctx.Err())
}()
return session.recvLoop()
}

Expand Down Expand Up @@ -72,6 +72,7 @@ func (c *serverSession) cleanup(err error) {
for _, stream := range c.streams {
_ = stream.pipe.CloseWithError(err)
}
c.streams = nil
c.streamAccess.Unlock()
}

Expand Down

0 comments on commit 7a74cdb

Please sign in to comment.