From 5d0dda688fb64cb5283944bcbd1e730c4e9176c5 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Mon, 27 Jun 2016 09:54:22 +0000 Subject: [PATCH] Make readLine more strict. --- parser.go | 12 +++++++----- race_test.go | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/parser.go b/parser.go index a58d3b1..f6e5ca6 100644 --- a/parser.go +++ b/parser.go @@ -1,6 +1,7 @@ package redis import ( + "bufio" "errors" "fmt" "net" @@ -19,9 +20,7 @@ const ( type multiBulkParser func(cn *pool.Conn, n int64) (interface{}, error) -var ( - errReaderTooSmall = errors.New("redis: reader is too small") -) +var errEmptyReply = errors.New("redis: reply is empty") //------------------------------------------------------------------------------ @@ -227,10 +226,13 @@ func scan(b []byte, val interface{}) error { func readLine(cn *pool.Conn) ([]byte, error) { line, isPrefix, err := cn.Rd.ReadLine() if err != nil { - return line, err + return nil, err } if isPrefix { - return line, errReaderTooSmall + return nil, bufio.ErrBufferFull + } + if len(line) == 0 { + return nil, errEmptyReply } if isNilReply(line) { return nil, Nil diff --git a/race_test.go b/race_test.go index 75ade87..ca4fb7f 100644 --- a/race_test.go +++ b/race_test.go @@ -120,7 +120,6 @@ var _ = Describe("races", func() { Expect(got).To(Equal(bigVal)) } }) - }) It("should handle big vals in Set", func() {