Skip to content

KAFKA-16448: Handle fatal user exception during processing error#16675

Merged
mjsax merged 5 commits intoapache:trunkfrom
sebastienviale:KAFKA-16448-Handle-Fatal-User-Exception-During-Processing-Error
Jul 31, 2024
Merged

KAFKA-16448: Handle fatal user exception during processing error#16675
mjsax merged 5 commits intoapache:trunkfrom
sebastienviale:KAFKA-16448-Handle-Fatal-User-Exception-During-Processing-Error

Conversation

@sebastienviale
Copy link
Copy Markdown
Contributor

This PR is part of KAFKA-16448 which aims to bring a ProcessingExceptionHandler to Kafka Streams in order to deal with exceptions that occur during processing.

This PR catch the exceptions thrown while handling a processing exception

Jira: https://issues.apache.org/jira/browse/KAFKA-16448.

Contributors
@Dabz
@sebastienviale
@loicgreffier

Copy link
Copy Markdown
Member

@cadonna cadonna left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @sebastienviale !

Here my comments!

} catch (final Exception fatalUserException) {
log.error(
"Processing error callback failed after processing error for record {}",
record,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should not log records for privacy reasons. The exception should be enough.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines +220 to +221
response = processingExceptionHandler
.handle(errorHandlerContext, record, e);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
response = processingExceptionHandler
.handle(errorHandlerContext, record, e);
response = processingExceptionHandler.handle(errorHandlerContext, record, e);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@cadonna cadonna added streams kip Requires or implements a KIP labels Jul 24, 2024
try {
response = processingExceptionHandler
.handle(errorHandlerContext, record, e);
} catch (final Exception fatalUserException) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please also add a unit test for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Member

@cadonna cadonna left a comment

Choose a reason for hiding this comment

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

Thanks for the updates!

LGTM!

try {
response = processingExceptionHandler.handle(errorHandlerContext, record, e);
} catch (final Exception fatalUserException) {
throw new StreamsException("Fatal user code error in processing error callback", fatalUserException);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we add an error log before throwing?

Btw: it seems we have such a guard only for the DeserializationExceptionHandler#handle(...) call, but not for the ProductionExceptionHanlder#call(...)? Might be good to do a follow up PR to add it to the proction-error-handler case, too?

Copy link
Copy Markdown
Member

@mjsax mjsax Jul 30, 2024

Choose a reason for hiding this comment

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

One more thing: if we throw StreamsException here, we might catch it in an upstream process(), right? So should we rather wrap this StreamsException with a FailedProcessingException?

Do we actually have a test for "passing through" of FailedProcessingException (ie, a test which checks if upstream ProcessingExceptionHandler are not called any longer, if a downstream processor had an error and the corresponding handler did return FAIL? If yes, we could re-use this test to also test a crashing handler. If not, let's add new tests for both cases :)

Copy link
Copy Markdown
Contributor Author

@sebastienviale sebastienviale Jul 30, 2024

Choose a reason for hiding this comment

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

done:
I changed the StreamException into a FailedProcessingException
and added some test to check that no more processor is executed when an exception occurs or when an exception occurs in a handler.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should we add an error log before throwing?

Btw: it seems we have such a guard only for the DeserializationExceptionHandler#handle(...) call, but not for the ProductionExceptionHanlder#call(...)? Might be good to do a follow up PR to add it to the proction-error-handler case, too?

@mjsax is it mandatory for this KIP ?

Copy link
Copy Markdown
Contributor

@loicgreffier loicgreffier Jul 30, 2024

Choose a reason for hiding this comment

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

One more thing: if we throw StreamsException here, we might catch it in an upstream process(), right? So should we rather wrap this StreamsException with a FailedProcessingException?

@mjsax Correct. FailedProcessingException is thrown as is:

Do we actually have a test for "passing through" of FailedProcessingException

We do:

public void shouldNotHandleInternalExceptionsThrownDuringProcessing(final String ignoredExceptionName,

It asserts FailedProcessingException is not handled and thrown as is. Another test has been added to ensure that the cause of the exception is from the processing exception handler (if it is actually thrown by it).

Copy link
Copy Markdown
Member

@mjsax mjsax Jul 31, 2024

Choose a reason for hiding this comment

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

Btw: it seems we have such a guard only for the DeserializationExceptionHandler#handle(...) call, but not for the ProductionExceptionHanlder#call(...)? Might be good to do a follow up PR to add it to the proction-error-handler case, too?

@mjsax is it mandatory for this KIP ?

Well, we don't want a handler which throws an exception to not crash KS, because the exception is caught in an upstream handler, right? But should be a simple thing to add?

But I see your point that it's not really related to the KIP. I can do a follow up myself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Btw: it seems we have such a guard only for the DeserializationExceptionHandler#handle(...) call, but not for the ProductionExceptionHanlder#call(...)? Might be good to do a follow up PR to add it to the proction-error-handler case, too?

@mjsax is it mandatory for this KIP ?

Well, we don't want a handler which throws an exception to not crash KS, because the exception is caught in an upstream handler, right? But should be a simple thing to add?

But I see your point that it's not really related to the KIP. I can do a follow up myself.

Ok, I will open a new PR for that !

@sebastienviale sebastienviale force-pushed the KAFKA-16448-Handle-Fatal-User-Exception-During-Processing-Error branch from 77d2ed2 to 4d50ab3 Compare July 29, 2024 14:16
@mjsax
Copy link
Copy Markdown
Member

mjsax commented Jul 30, 2024

@sebastienviale -- The PR has merge conflicts and needs to be rebased.

Maybe also address the open comments from the other PRs on this one.

@sebastienviale sebastienviale force-pushed the KAFKA-16448-Handle-Fatal-User-Exception-During-Processing-Error branch from 9661027 to 9c6f40e Compare July 30, 2024 06:48
Co-authored-by: Dabz <d.gasparina@gmail.com>
Co-authored-by: loicgreffier <loic.greffier@michelin.com>

KAFKA-16448 Handle fatal user exception during processing error

Co-authored-by: Dabz <d.gasparina@gmail.com>
Co-authored-by: loicgreffier <loic.greffier@michelin.com>

KAFKA-16448 Handle fatal user exception during processing error

Co-authored-by: Dabz <d.gasparina@gmail.com>
Co-authored-by: loicgreffier <loic.greffier@michelin.com>

KAFKA-16448 Handle fatal user exception during processing error

Co-authored-by: Dabz <d.gasparina@gmail.com>
Co-authored-by: loicgreffier <loic.greffier@michelin.com>

KAFKA-16448 Handle fatal user exception during processing error

Co-authored-by: Dabz <d.gasparina@gmail.com>
Co-authored-by: loicgreffier <loic.greffier@michelin.com>
@sebastienviale sebastienviale force-pushed the KAFKA-16448-Handle-Fatal-User-Exception-During-Processing-Error branch from 9c6f40e to 2be7af8 Compare July 30, 2024 06:50
sebastienviale and others added 4 commits July 30, 2024 15:33
Co-authored-by: Dabz <d.gasparina@gmail.com>
Co-authored-by: loicgreffier <loic.greffier@michelin.com>
Co-authored-by: Dabz <d.gasparina@gmail.com>
Co-authored-by: loicgreffier <loic.greffier@michelin.com>
@mjsax mjsax merged commit 0dc9b9e into apache:trunk Jul 31, 2024
mjsax pushed a commit that referenced this pull request Jul 31, 2024
)

This PR is part of KIP-1033 which aims to bring a ProcessingExceptionHandler to Kafka Streams in order to deal with exceptions that occur during processing.

This PR catch the exceptions thrown while handling a processing exception

Co-authored-by: Dabz <d.gasparina@gmail.com>
Co-authored-by: loicgreffier <loic.greffier@michelin.com>

Reviewers: Bruno Cadonna <bruno@confluent.io>, Matthias J. Sax <matthias@confluent.io>
@mjsax
Copy link
Copy Markdown
Member

mjsax commented Jul 31, 2024

Thanks for the PR. Merged to trunk and cherry-picked to 3.9 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kip Requires or implements a KIP streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants