-
Notifications
You must be signed in to change notification settings - Fork 344
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: producer close was blocked #1249
Conversation
a3cec27
to
34a0678
Compare
89b9e84
to
8900751
Compare
Hi @nodece , I think calling The root cause of this bug is that the event loop is stuck in an infinite loop in reconnectToBroker(), I think infinite loop in a case of select{case...} is not a good design, we can run the infinite loop in a seperate goroutine, like this: case connectionClosed := <-p.connectClosedCh:
p.log.Info("runEventsLoop will reconnect in producer")
// Start a new goroutine for reconnecting to broker
go p.reconnectToBroker(connectionClosed) when the producer is closed, it will quit at: if p.getProducerState() != producerReady {
// Producer is already closing
p.log.Info("producer state not ready, exit reconnect")
return
} |
The reconnect request should block the send and flush requests. We can also use The close request shouldn't be added to the event loop, otherwise, the close request will be blocked when reconnecting. |
OK, since |
@gunli Good catch, we should improve the event loop, once the producer is closed, the event loop should be stopped. |
@gunli +1 |
@gunli @RobertIndie The Event:
|
But the behavior is unpredictable as they are run in different goroutines, after |
a6f8656
to
1619213
Compare
Updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR may be related to issue #1190 |
* fix: producer close was blocked * Fix lint * Use ctx to control logic * Reduce timeout * Improve style (cherry picked from commit 28293a6)
Closes #1190
Motivation
When the producer keeps reconnecting to the broker in the event loop, at the same time, the user calls
producer.Close
, the producer cannot be closed, because the event loop is executing the reconnect request.Modifications
testcontainers
requires go 1.21.Verifying this change
Added test.