IBM / sarama

Sarama is a Go library for Apache Kafka.
MIT License
11.57k stars 1.76k forks source link

[Question]how can i recover from panic while using consume group #2105

Closed Rorke76753 closed 1 year ago

Rorke76753 commented 2 years ago

I wrote my recovery code like this

func (b MyWrapConsumer) Consume(ctx context.Context, handler *WrapHandler) {
//WrapHandler which implements ConsumerGroupHandler
    defer func() {
        if err := recover(); err != nil {
            //do some log
        }
                 b.Consume(ctx,handler)
    }()
    for {
        err := b.consumerGroup.Consume(ctx, b.topics, handler)
        if err != nil {
            //do some log
        }
    }
}

I figured out that the recover does not work, should i put the recovery code into WrapHandler.ConsumeClaim?

dnwe commented 2 years ago

hmm, consumerGroup.Consume itself shouldn't be panic'ing, it only calls internal Sarama code — do you have an example of a panic you've seen?

If the panic is in your own code then yes it would need to be in your implementation of the ConsumerGroupHandler interface

github-actions[bot] commented 1 year ago

Thank you for taking the time to raise this issue. However, it has not had any activity on it in the past 90 days and will be closed in 30 days if no updates occur. Please check if the main branch has already resolved the issue since it was raised. If you believe the issue is still valid and you would like input from the maintainers then please comment to ask for it to be reviewed.

dnwe commented 1 year ago

Closing as presumed to have been solved. Please reopen if not