-
Notifications
You must be signed in to change notification settings - Fork 14.3k
KAFKA-19171: Kafka Streams crashes with UnsupportedOperationException #19507
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
Open
mjsax
wants to merge
3
commits into
apache:trunk
Choose a base branch
from
mjsax:kafka-19171-ks-crash-unsupported-operation-exception
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is it necessary to call
closeDirty
for those failed tasks?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.
Good point. I guess yes.
Originally we did not use
closetTaskClean()
but the PR introducing this change started to use it: #16730I did not dig into the original PR, but it seems there was some issue with leaking resources in tests? So maybe it's just a test issue?
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.
I am frankly not sure, why #16730 would actually address any resource leak, as the old and new code would just call
The difference is just, that the new code would catch and swallow potential exceptions.
So maybe if we throw some exception, other cleanup code did not run leaking the producer? But with the new code, we would swallow the exception ensuring that other cleanup code does run?
Would be good to understand better. Maybe @FrankYang0529 can shed some light?
I am not 100% sure right now, if #16730 is the correct fix for the leak or not.
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.
It's actually not even clear to me, how a "pending task to init" could fail to close clean to begin with... \cc @cadonna @lucasbru @ableegoldman and ideas?
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.
The leak resource was found by #14783. On that branch, the leak resource only happened for the case
EosIntegrationTest#shouldCheckpointRestoredOffsetsWhenClosingCleanDuringRestoringStateUpdaterEnabled(eosConfig=StreamsConfig.EXACTLY_ONCE, processingThreadsEnabled="false")
. I think it's safe to revert the change cause of the EOSv1 was removed in 4.0.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.
Thanks @FrankYang0529 -- still not sure right now if just reverting is the right thing:
This is the thing that worries me -- we did see it crash with EOSv2, so some pending tasks did get revoked and there was an error during revocation. So maybe we did expose some different bug.
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.
I was looking into the logs we collected more plus the code, and it seems possible that we get an error on close with EOSv2.
When we close the unitized tasks, we close the
RecordCollector
and we check for pending errors: https://github.com/apache/kafka/blob/4.0/streams/src/main/java/org/apache/kafka/streams/processor/internals/RecordCollectorImpl.java#L568Because we shared a single producer across multiple tasks, the initialized task could observe an error from some other task. -- So it seems to be actually safe to swallow this exception when closing a pending task. It's just not totally clear to me, how/where to implement this swallowing correctly? The simples way might be to close pending task dirty, but not sure if that's really the right way to do it (would also result in confusing logging...) -- or we really just try to close clean, and for any task with error close dirty afterwards?
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.
I believe something like in the following code, will avoid the leak:
kafka/streams/src/main/java/org/apache/kafka/streams/processor/internals/TaskManager.java
Line 1325 in efd7852
Basically, we need to collect the failed tasks in
tasksToCloseDirty
and close those tasks dirty. The thrown exception is swallowed.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.
@cadonna 's suggestion makes sense to me
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.
Thanks, agree. It was also what @chia7712 original comment was about:
It was originally just not clear to me, why a uninitilzied task could fail.