From 84740b676a54c09b2bd5246d278d3a25dedb2686 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Sat, 19 Nov 2016 22:40:14 +0100 Subject: [PATCH] handle empty payload --- proxy/shadowsocks/client.go | 6 ++++-- proxy/testing/mocks/outboundhandler.go | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/proxy/shadowsocks/client.go b/proxy/shadowsocks/client.go index dc32fface..f19c4c4c4 100644 --- a/proxy/shadowsocks/client.go +++ b/proxy/shadowsocks/client.go @@ -142,8 +142,10 @@ func (this *Client) Dispatch(destination v2net.Destination, payload *alloc.Buffe Writer: conn, Request: request, } - if err := writer.Write(payload); err != nil { - return errors.New("Shadowsocks|Client: Failed to write payload: " + err.Error()) + if !payload.IsEmpty() { + if err := writer.Write(payload); err != nil { + return errors.New("Shadowsocks|Client: Failed to write payload: " + err.Error()) + } } v2io.Pipe(ray.OutboundInput(), writer) diff --git a/proxy/testing/mocks/outboundhandler.go b/proxy/testing/mocks/outboundhandler.go index 5579fc7a9..c1a6e7113 100644 --- a/proxy/testing/mocks/outboundhandler.go +++ b/proxy/testing/mocks/outboundhandler.go @@ -23,7 +23,9 @@ func (this *OutboundConnectionHandler) Dispatch(destination v2net.Destination, p output := ray.OutboundOutput() this.Destination = destination - this.ConnOutput.Write(payload.Value) + if !payload.IsEmpty() { + this.ConnOutput.Write(payload.Value) + } payload.Release() writeFinish := &sync.Mutex{}