From 49ea8c0ec17715f30929c03b2bf2262b3a3bc492 Mon Sep 17 00:00:00 2001 From: Graham Barr Date: Mon, 18 Aug 2014 09:51:33 -0500 Subject: [PATCH 1/2] Increase buffer size to 8K --- client/common.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/common.go b/client/common.go index ad47936..e520bf0 100644 --- a/client/common.go +++ b/client/common.go @@ -5,7 +5,7 @@ const ( // queue size queueSize = 8 // read buffer size - bufferSize = 1024 + bufferSize = 8192 // min packet length minPacketLength = 12 From d82da8fd71a5eb52ce22ada7e7f8df06e7f39c08 Mon Sep 17 00:00:00 2001 From: Graham Barr Date: Mon, 18 Aug 2014 09:58:28 -0500 Subject: [PATCH 2/2] Avoid read channel corruption when response size > bufferSize When receiving a response, what was happening 1. Read bufferSize and it gets assigned to leftdata 2. Read another bufferSize 3. 2 buffers get appended, but leftdata still points to first buffer 4. Process data buffer which contains only complete responses 5. Back to ReadLoop, but leftdata still points to first incomplete buffer causing corrupt data to be processed Solution is to make leftdata nil once we have merged it with the second buffer --- client/client.go | 1 + 1 file changed, 1 insertion(+) diff --git a/client/client.go b/client/client.go index b2a8c00..55ca858 100644 --- a/client/client.go +++ b/client/client.go @@ -104,6 +104,7 @@ ReadLoop: } if len(leftdata) > 0 { // some data left for processing data = append(leftdata, data...) + leftdata = nil } for { l := len(data)