Repository navigation
Conversation
|
is this issue affecting the Go client only or other clients as well ? |
Hi @alexku7, if you run the test I posted and set up a few breakpoints you'll realize that this is a Golang library issue. I tried with Python multiple times and it never got deadlocked while acking. Have you noticed that the |
|
|
Thanks @fracasula feedback, Here I tried to use the simplest code to simulate this problem, unfortunately, I did not reproduce it. |
Hi @wolfstudy, I don't understand why you're trying to replicate the bug with that code, it would be nearly impossible. I invite you to read the description of the issue in my first post again, I'll post it here below for convenience:
If you want a good chance to reproduce it YOU MUST try to have as much in-flight This way you'll have a good chance to replicate the deadlock which, in order to happen, would need at least 3 in-flight Please do run the test I provided that is already reproducing the bug, it doesn't take much to reverse engineer. |
|
Hi @fracasula , I checkout to execute it in your current branch and used the test case you provided and tried to run more than 10 times locally. I didn't reproduce. The locality can work normally. The only change is that I encountered a And the output as follows: Output: |
|
I dump the log file of the test case |
|
@fracasula does increasing the events channel buffer help? That number was kind of randomly picked. I would suggest to go ahead a put up a fix. |
|
All requests in the go client will enter the incomingRequestChannel, and then the request will be processed in the runEventsLoop. incomingRequestChannel is a channel with a buffer. When the size of the buffer is reached, it will wait for the consumer in the channel (different from the consumer of pulsar) to consume data. In the current processing of the go client, there is no incomingRequestChannel close logic. We previously thought that after closing the consumer and closing the connection, all the corresponding states need to be cleaned up. But in fact, there was no suitable time to close the channel that received the request. First: After closing the connection, it will immediately enter the logic of reconnection. At this time, you still need to use incomingRequestChannel to receive data. In my repeated attempts to reproduce locally, I only encountered the following errors: This error has nothing to do with the problem itself. It is caused by the context timeout. We try to increase the context timeout to avoid this problem. |
|
@wolfstudy it may not be a client issue as I mentioned in my last post in this other thread and in our email correspondence. If you look at the video I sent you at 4:20 it shows that there are no consumers connected despite the connection being open. I can see the ping and pongs travelling back and forth with The test also prints the following which is mostly from your library: Yet the consumer is stuck and doesn't proceed with message consumption. May it be the broker not sending the messages? As you can see from the video I'm using the latest image (i.e. I also raised the max unacked messages per consumer and per subscription by doing statsstats-internal |
|
@jiazhai How about move the consumer and producer listener's ConnectionClosed() code https://github.com/apache/pulsar-client-go/blob/master/pulsar/internal/connection.go#L763 I hope that can guarantee close of handlers. It becomes something like |
Fixes #366 ### Motivation In current code of `pulsar/internal/connection.go` we have 2 channels, closeCh and incomingRequestsCh. when the connection closes, the current mis-use of these 2 channels may have a deadlock. PR #366 has detailed steps to reproduce and the root cause [analysis](#366 (comment)) . This PR tries to fix the deadlock. ### Modifications - make the close logic independent, not in the same loop of normal events handling. - when the connection closed, handle the existing requests in the channel and return an error to avoid deadlock. ### Verifying this change passed the tests in #366 current ut passed










Motivation
This is an integration test built with the intent of replicating the bug reported in this issue. I opened this PR to gather some feedback before working on a fix.
A possible solution would be to move the
connectionClosedevents out of theeventsChchannel and have them into their own channel (e.g.connectionEventsCh): https://github.com/apache/pulsar-client-go/blob/master/pulsar/consumer_partition.go#L752This is because some of the events travelling through the
eventsChchannel rely on an open connection to finish. So if theeventsChchannel gets full with, say, in-flightackRequestevents, theconnectionClosedevent cannot be processed until theackRequestare finished and theackRequestcannot finish because the connection is closed and theconnectionClosedevent (which should trigger a reconnection to the broker) is stuck waiting to be pushed to theeventsChchannel.Given that the
connectionClosedevent is needed to trigger a reconnection to the broker I think it could make sense to have it in a separate channel.If this approach sounds sensible to you I can start making modifications.
Replicate the bug
The test doesn't always fail, you'll have to try again. In my case it fails 1 out of 3 times (more or less).
So if you run it just once and you see the test complete instead of failing, then please run it again.
Once the test fails you should see that it timed out after five minutes and that it printed a lot of logs saying
Trying to ack {messageID}.Please check the attached
deadlock.zipwhich shows the logs of a failing test.Running the test
dockerrunning and usable from the user that runs the testdocker pull apachepulsar/pulsar:2.6.1firstgo test ./pulsar/ -test.run ^TestDeadlock$ -v -tags integration -count 1deadlock.zip