pulsar-client-go icon indicating copy to clipboard operation
pulsar-client-go copied to clipboard

ReconsumeLater cause panic

Open elvizlai opened this issue 3 years ago • 4 comments

Expected behavior

should be ReconsumeLater

Actual behavior

Panic when call ReconsumeLater

With version 0.6.0 https://github.com/apache/pulsar-client-go/blob/fe3b7c4e445b3de42974ca692574229ad9099a45/pulsar/consumer_impl.go?_pjax=%23js-repo-pjax-container%2C%20div%5Bitemtype%3D%22http%3A%2F%2Fschema.org%2FSoftwareSourceCode%22%5D%20main%2C%20%5Bdata-pjax-container%5D#L481

same panic for 0.7

github.com/apache/pulsar-client-go@v0.7.0-candidate-1.0.20211108044248-fe3b7c4e445b/pulsar/consumer_impl.go:481 +0x6ca

Steps to reproduce

	client, err := pulsar.NewClient(pulsar.ClientOptions{
		URL: addr,
	})
	if err != nil {
		panic(err)
	}

	consumer, err := client.Subscribe(pulsar.ConsumerOptions{
		Topic:            "test",
		SubscriptionName: "xyz",
	})
	if err != nil {
		panic(err)
	}

        for {
	        select {
	        case cm := <-consumer.Chan():
		        fmt.Println(string(cm.Payload()))
		        cm.ReconsumeLater(cm.Message,time.Second)
	        }
        }

System configuration

Pulsar version: 0.6.0

elvizlai avatar Nov 10 '21 06:11 elvizlai

Can you share more of the stack trace? Does this happen every time you call ReconsumeLater? If not what are the steps to reproduce?

cckellogg avatar Nov 10 '21 22:11 cckellogg

time

For missing DQL consumer, it will cause panic.

elvizlai avatar Nov 10 '21 23:11 elvizlai

yes, you should have a dql, then you can ReconsumeLater

the panic maybe not friendly

	// ReconsumeLater mark a message for redelivery after custom delay
	ReconsumeLater(msg Message, delay time.Duration)

the better way ,we need return a error for this method.

leizhiyuan avatar Dec 23 '21 11:12 leizhiyuan

you can use

consumer, err := client.Subscribe(pulsar.ConsumerOptions{
		Topic:            "topic-1",
		SubscriptionName: "my-sub",
		Type:             pulsar.Exclusive,
		DLQ:              &pulsar.DLQPolicy{MaxDeliveries: 1,DeadLetterTopic: "dlq-topic"},
	})

to solve this. it is helpful

leizhiyuan avatar Dec 23 '21 11:12 leizhiyuan