Skip to content

Invalid memory address or nil pointer when write commands in function _backgroundWrite #702

@gj3233

Description

@gj3233

Hello,
Yesterday when testing with redis cluster, my application had been panic at line ( (of rueidis v1.0.46) :
return c.cs.s which in function Commands():
func (c *Completed) Commands() []string { return c.cs.s }
which is call by err = writeCmd(p.w, cmd.Commands())
image

The complete code is:
`func (p *pipe) _backgroundWrite() (err error) {
var (
ones = make([]Completed, 1)
multi []Completed
ch chan RedisResult
flushDelay = p.maxFlushDelay
flushStart = time.Time{}
)

for err == nil {
	if ones[0], multi, ch = p.queue.NextWriteCmd(); ch == nil {
		if flushDelay != 0 {
			flushStart = time.Now()
		}
		if p.w.Buffered() != 0 {
			if err = p.w.Flush(); err != nil {
				break
			}
		}
		ones[0], multi, ch = p.queue.WaitForWrite()
		if flushDelay != 0 && atomic.LoadInt32(&p.waits) > 1 { // do not delay for sequential usage
			// Blocking commands are executed in dedicated client which is acquired from pool.
			// So, there is no sense to wait other commands to be written.
			// https://github.com/redis/rueidis/issues/379
			var blocked bool
			for i := 0; i < len(multi) && !blocked; i++ {
				blocked = multi[i].IsBlock()
			}
			if !blocked {
				time.Sleep(flushDelay - time.Since(flushStart)) // ref: https://github.com/redis/rueidis/issues/156
			}
		}
	}
	if ch != nil && multi == nil {
		multi = ones
	}
	for _, cmd := range multi {
		err = writeCmd(p.w, cmd.Commands())
	}
}
return

}`

Redis topology:
cluster enabled
3 master 3 replica

Action: Node is starting.

Could you help on this? Thanks. It seems cmd passed to writeCmd() has something wrong that lead to the crash. It confused because cmd is read from range multi, so I think something wrong happened to multi.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions