Skip to content

Commit

Permalink
Fix another minor arraystack bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ammario committed Feb 13, 2024
1 parent d4203d1 commit 4515ec6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (r *Pipeline) writeTo(w io.Writer) (int64, replyType, error) {
typ := replyType(typByte)

// incrRead is how we advance the read state machine.
incrRead := func() {
incrRead := func(isNewArray bool) {
if len(r.arrayStack) == 0 {
r.pipeline.at++
return
Expand All @@ -292,7 +292,10 @@ func (r *Pipeline) writeTo(w io.Writer) (int64, replyType, error) {
i := len(r.arrayStack) - 1
r.arrayStack[i] = r.arrayStack[i] - 1

if r.arrayStack[i] == 0 {
// We don't do this cleanup on new arrays so that
// we can support stacks like [0, 2] for the final
// list in a series of lists.
if r.arrayStack[i] == 0 && !isNewArray {
r.arrayStack = r.arrayStack[:i]
// This was just cleanup, we move the pipeline forward.
r.pipeline.at++
Expand All @@ -313,7 +316,7 @@ func (r *Pipeline) writeTo(w io.Writer) (int64, replyType, error) {

var n int
n, r.err = w.Write(s)
incrRead()
incrRead(isNewArray)
var newArraySize int
if isNewArray {
var err error
Expand All @@ -331,15 +334,15 @@ func (r *Pipeline) writeTo(w io.Writer) (int64, replyType, error) {
// Bulk string
var n int
n, r.err = readBulkString(w, r.conn, r.conn.rd, r.conn.miscBuf)
incrRead()
incrRead(false)
return int64(n), typ, r.err
case replyTypeError:
// Error
s, r.err = readUntilNewline(r.conn.rd, r.conn.miscBuf)
if r.err != nil {
return 0, typ, r.err
}
incrRead()
incrRead(false)
return 0, typ, &Error{
raw: string(s),
}
Expand Down

0 comments on commit 4515ec6

Please sign in to comment.