Skip to content

Conversation

@Interval-0
Copy link

Title goes desc. lol

@asheswook
Copy link
Member

Welcome, Interval-0. Thank you for your first contribution!

@asheswook asheswook added enhancement New feature or request good first issue Good for newcomers labels Jun 11, 2024
msg.DataChan = make(chan *sarama.ConsumerMessage, 1)

go func() {
defer close(msg.DataChan)
Copy link
Member

Choose a reason for hiding this comment

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

Closing the channel is used as a signal that the channel is no longer in use. It is not related to memory leaks. So, 'close' should be called when the data transfer ends, rather than when the goroutine ends (defer).

Copy link
Member

Choose a reason for hiding this comment

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

In this case deleted the code line (close) below and used the defer instead.

for {
retryCount := 0
maxRetries := 30
for retryCount < maxRetries {
Copy link
Member

Choose a reason for hiding this comment

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

A transaction must be canceled if some error occurs, for exactly-once. So this is good for infinite loop, but this doesn't look good for business policy. In my opinion, it would be better to delay processing (time.Sleep) or log if cross the attempt threshold in a loop. (actually my suggestion is another business feature)

Copy link
Member

Choose a reason for hiding this comment

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

If a transaction error occurs, it will one day be processed if the producer is okay, so no worry to infinite loop. If there is a problem with the producer, it is prevented by handling producer.TxnStatus()& sarama.ProducerTxnFlagFatalError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants