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

Try to fix race again - don't reuse clients for sender/receiver #971

Merged
merged 1 commit into from
Oct 28, 2023

Conversation

duglin
Copy link
Contributor

@duglin duglin commented Oct 25, 2023

from: https://pkg.go.dev/github.com/shopify/sarama#NewConsumerGroupFromClient


NewConsumerGroupFromClient creates a new consumer group using the given client. It is still necessary to call Close() on the underlying client when shutting down this consumer. PLEASE NOTE: consumer groups can only re-use but not share clients.


I'm not 100% sure if using the same client for sending and receiving qualifies for this restriction or not but let's see if this works w/o the "sleeps". Seems to work locally for me.

So, this PR just creates 2 clients (one for sending and one for receiving) instead of trying to reuse the same one for both.

@duglin
Copy link
Contributor Author

duglin commented Oct 25, 2023

@embano1 I ran the tests several times via the "checks" and they seem happy. I did see some weirdness in the mqtt stuff but we can look at that separately - haven't seen a kafka complaint yet. Thoughts?

Copy link
Member

@embano1 embano1 left a comment

Choose a reason for hiding this comment

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

Minor nit.

And IMHO this should fix the races as my understanding from prior code digging was the race due to sharing the same Kafka client in the test racing against the broker with concurrent function calls during producer/consumer initialization.

topicName := "test-ce-client-" + uuid.New().String()
p, err := kafka_sarama.NewProtocolFromClient(client, topicName, topicName, kafka_sarama.WithReceiverGroupId(TEST_GROUP_ID))

clientR := testClient(t)
Copy link
Member

Choose a reason for hiding this comment

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

nit: please add a code comment or better variable name to indicate what the R and S suffixes on client and p mean so our future-selves have an easier time understanding the change :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - I can barely remember why/what I did yesterday so this is a good "nit" :-)

@embano1 embano1 merged commit 24f0eb4 into cloudevents:main Oct 28, 2023
17 checks passed
@duglin duglin deleted the moreRace branch October 29, 2023 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants