From 67db5830be5462006fd59bc629faf00235112652 Mon Sep 17 00:00:00 2001 From: v2ray Date: Sat, 7 May 2016 09:53:15 +0200 Subject: [PATCH] agreesively close rays --- proxy/freedom/freedom.go | 1 + proxy/shadowsocks/shadowsocks.go | 2 +- proxy/vmess/inbound/inbound.go | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index d29d8721..ee081428 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -68,6 +68,7 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload * defer v2reader.Release() v2io.Pipe(v2reader, output) + ray.OutboundOutput().Close() }() writeMutex.Lock() diff --git a/proxy/shadowsocks/shadowsocks.go b/proxy/shadowsocks/shadowsocks.go index 410ebe9d..f47fc96e 100644 --- a/proxy/shadowsocks/shadowsocks.go +++ b/proxy/shadowsocks/shadowsocks.go @@ -205,6 +205,7 @@ func (this *Shadowsocks) handleConnection(conn *hub.Connection) { log.Info("Shadowsocks: Tunnelling request to ", dest) ray := this.packetDispatcher.DispatchToOutbound(dest) + defer ray.InboundOutput().Release() var writeFinish sync.Mutex writeFinish.Lock() @@ -227,7 +228,6 @@ func (this *Shadowsocks) handleConnection(conn *hub.Connection) { v2writer := v2io.NewAdaptiveWriter(writer) v2io.Pipe(ray.InboundOutput(), v2writer) - ray.InboundOutput().Release() writer.Release() v2writer.Release() } diff --git a/proxy/vmess/inbound/inbound.go b/proxy/vmess/inbound/inbound.go index bf848304..69a1fa35 100644 --- a/proxy/vmess/inbound/inbound.go +++ b/proxy/vmess/inbound/inbound.go @@ -139,6 +139,9 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) { ray := this.packetDispatcher.DispatchToOutbound(request.Destination()) input := ray.InboundInput() output := ray.InboundOutput() + defer input.Close() + defer output.Release() + var readFinish, writeFinish sync.Mutex readFinish.Lock() writeFinish.Lock() @@ -189,7 +192,6 @@ func (this *VMessInboundHandler) HandleConnection(connection *hub.Connection) { if request.Option.IsChunkStream() { writer.Write(alloc.NewSmallBuffer().Clear()) } - output.Release() writer.Release() finish.Unlock() }(&writeFinish)