Skip to content

Commit

Permalink
Don't write to channel if closed. Fixes hoisie#18.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Aigner committed May 24, 2013
1 parent f1b3e0c commit 01d27cc
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 01d27cc

Please sign in to comment.