Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/rebalancing #30

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/kafka/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ func (h messageHandler) processMessage(
msg.SetContext(ctx)
defer cancelCtx()

// check session has been canceled after rebalancing
sessionContext := sess.Context()

receivedMsgLogFields = receivedMsgLogFields.Add(watermill.LogFields{
"message_uuid": msg.UUID,
})
Expand All @@ -578,6 +581,9 @@ ResendLoop:
case <-ctx.Done():
h.logger.Trace("Closing, ctx cancelled before sent to consumer", receivedMsgLogFields)
return nil
case <-sessionContext.Done():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this fail since sess is nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Session can't be nil. Saram won't start consuming in such case. By the way sarama does the same check before consuming starts, but if rebalancing started after, during processing messages, it hangs on trying commit offset with staled session.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've overlooked it. Fixed this.

h.logger.Trace("Closing, session ctx cancelled before sent to consumer", receivedMsgLogFields)
return nil
}

select {
Expand All @@ -603,6 +609,9 @@ ResendLoop:
case <-ctx.Done():
h.logger.Trace("Closing, ctx cancelled before ack", receivedMsgLogFields)
return nil
case <-sessionContext.Done():
h.logger.Trace("Closing, session ctx cancelled before ack", receivedMsgLogFields)
return nil
}
}

Expand Down