From 01d27cc719e6488ccfdf538b8993680fc98f414d Mon Sep 17 00:00:00 2001 From: Erik Aigner Date: Fri, 24 May 2013 22:22:50 +0200 Subject: [PATCH] Don't write to channel if closed. Fixes #18. --- redis.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/redis.go b/redis.go index 68c1a57..190a914 100644 --- a/redis.go +++ b/redis.go @@ -216,6 +216,7 @@ func (client *Client) sendCommands(cmdArgs <-chan []string, data chan<- interfac var reader *bufio.Reader var pong interface{} var errs chan error + var errsClosed = false if err != nil { goto End @@ -251,23 +252,33 @@ func (client *Client) sendCommands(cmdArgs <-chan []string, data chan<- interfac for cmdArg := range cmdArgs { err = writeRequest(c, cmdArg[0], cmdArg[1:]...) if err != nil { - errs <- err + if !errsClosed { + errs <- err + } break } } - close(errs) + if !errsClosed { + errsClosed = true + close(errs) + } }() go func() { for { response, err := readResponse(reader) if err != nil { - errs <- err + if !errsClosed { + errs <- err + } break } data <- response } - close(errs) + if !errsClosed { + errsClosed = true + close(errs) + } }() // Block until errs channel closes