-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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][Client] Fix pending message not complete when closeAsync #23761
Conversation
There's a related issue #11780 |
There's also #12195 |
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 makes sense.
I initially thought that the intention was to also address issues #11780 and #12195 as well. There could be a separately improvement addressing the problem that closeAsync doesn't flush any pending messages before closing. Usually there's an expectation coming from java.io.OutputStream that when you call close, it will flush before closing. This doesn't happen with Producer's close.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #23761 +/- ##
============================================
+ Coverage 73.57% 74.32% +0.75%
+ Complexity 32624 32146 -478
============================================
Files 1877 1838 -39
Lines 139502 143048 +3546
Branches 15299 16232 +933
============================================
+ Hits 102638 106323 +3685
+ Misses 28908 28355 -553
- Partials 7956 8370 +414
Flags with carried forward coverage won't be shown. Click here to find out more.
|
(cherry picked from commit e0a9e4c)
(cherry picked from commit e0a9e4c)
(cherry picked from commit e0a9e4c)
Motivation
In the current process of closeAsync() in ProducerImpl.java, the client will firstly set the producer to the Closing state, then stop timerTask of sendTimeout, and then send a http request to broker to close the producer. When the client receives a successful response from broker, it sets the producer to the Closed state, removes the producer from the producers in client, and complete the PendingMessage with AlreadyClosedException.
However, if the communication between client and broker is abnormal due to network or other reasons, the PendingMessage will not be cleared anymore. What's worse is that since the producer is already in the Closing state at this time, there is no chance to trigger the cleanup of PendingMessage by calling the closeAsync() again, which is obviously unreasonable.
Modifications
There is no need to wait for the broker's response to clean up PendingMessage. Once you decide to shut down the producer, there is no need to retain the PendingMessage in the producer. At this time, failing quickly is more valuable than waiting.
Verifying this change
Add a test case to ensure closeAndClearPendingMessages() has been invoke when request broker error after closeAsync().
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: