Skip to content

[BUG] consumer panic if queueCh receive a message with size 0 #1454

@unJASON

Description

@unJASON

Expected behavior

No panic.

Actual behavior

panic: runtime error: index out of range [0] with length 0

goroutine 10127 [running]:
github.com/apache/pulsar-client-go/pulsar.(*partitionConsumer).dispatcher(0xc008556000)
	D:/myGo/pkg/mod/github.com/apache/pulsar-client-go@v0.17.0/pulsar/consumer_partition.go:1721 +0xf94
created by github.com/apache/pulsar-client-go/pulsar.newPartitionConsumer in goroutine 9173
	D:/myGo/pkg/mod/github.com/apache/pulsar-client-go@v0.17.0/pulsar/consumer_partition.go:460 +0x161f

I think MessageReceived in consumer_partition.go may be the problem.

The for loop in MessageReceived may just continue instead of adding a element in the messages in some situation.

we may add some codes before adding to queueCh at the end. of MessageReceived like:

	if (len(messages) == 0){
		return nil
	}

	// send messages to the dispatcher
	pc.queueCh <- messages
	return nil

Steps to reproduce

How can we reproduce the issue
create 100 topic.

For each topic , create a producer and a consumer. Keep consuming messages.

While reset the cursor with timestamp infinitely.

System configuration

Pulsar version: 2.6.x

pulsar-client-go 0.17.0

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