Skip to content

GH-3618: Support CommonErrorHandler for suspend functions#4254

Merged
artembilan merged 5 commits into
spring-projects:mainfrom
zooo-code:GH-3618
Mar 13, 2026
Merged

GH-3618: Support CommonErrorHandler for suspend functions#4254
artembilan merged 5 commits into
spring-projects:mainfrom
zooo-code:GH-3618

Conversation

@zooo-code

Copy link
Copy Markdown
Contributor

Fixes GH-3618(#3618)

Summary

Support CommonErrorHandler (e.g., DefaultErrorHandler) for Kotlin suspend functions.

Previously, exceptions from suspend functions were only logged and not propagated to CommonErrorHandler. This change sets up the async failure callback for RecordMessagingMessageListenerAdapter when CommonErrorHandler is explicitly configured.

Changes

  • Setup async failure callback when CommonErrorHandler is explicitly configured
  • Add test for suspend function with CommonErrorHandler in EnableKafkaKotlinCoroutinesTests.kt

Related

Thanks!!

Please let me know if any changes are needed. I'm happy to address any feedback promptly.

@artembilan artembilan left a comment

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.

Please, add your name to the @author list of all the affected classes.
Thank you!

@zooo-code

Copy link
Copy Markdown
Contributor Author

@artembilan I've updated the PR based on your guidance. Please review when you have time!

Changes

  • Removed the getCommonErrorHandler() != null condition — now always set setCallbackForAsyncFailure() on RecordMessagingMessageListenerAdapter
  • Fixed 3 failing ObservationTests (obs6/obs7) by configuring a no-retry error handler (FixedBackOff(0, 0))
  • All tests pass

Regarding #4333: this PR addresses the same root cause.

@zooo-code zooo-code requested a review from artembilan March 11, 2026 09:11
Fixes spring-projectsGH-3618(spring-projects#3618)

* Setup async failure callback when CommonErrorHandler is explicitly configured
* Add test for suspend function with CommonErrorHandler

Signed-off-by: zoo-code <kyj20908@naver.com>
Fixes spring-projectsGH-3618 (spring-projects#3618)

* Set up async failure callback on RecordMessagingMessageListenerAdapter using generic delegation extraction via DelegatingMessageListener
* Add suspend function with CommonErrorHandler test in EnableKafkaKotlinCoroutinesTests
* Fix ObservationTests (obs6/obs7) with no-retry error handler

Signed-off-by: zoo-code <kyj20908@naver.com>

@artembilan artembilan left a comment

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.

Just one concern to see if we can make code better.

Thanks

…atching

Signed-off-by: zoo-code <kyj20908@naver.com>
Signed-off-by: zoo-code <kyj20908@naver.com>
@zooo-code zooo-code requested a review from artembilan March 12, 2026 23:04

@artembilan artembilan left a comment

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.

Sounds good!
Thank you for investigation and confirmation that I am wrong.
Merging...

@artembilan artembilan enabled auto-merge (squash) March 13, 2026 13:43
@artembilan

Copy link
Copy Markdown
Member

@zooo-code ,

thank you for contribution; looking forward for more!

@artembilan artembilan closed this Mar 13, 2026
auto-merge was automatically disabled March 13, 2026 13:44

Pull request was closed

@artembilan artembilan reopened this Mar 13, 2026
@artembilan artembilan enabled auto-merge (squash) March 13, 2026 13:44
@artembilan

Copy link
Copy Markdown
Member

Sorry, closed too early.
It will be closed automatically when PR build is green.

Thanks again!

@artembilan artembilan merged commit 813f689 into spring-projects:main Mar 13, 2026
5 checks passed
@zooo-code

Copy link
Copy Markdown
Contributor Author

@artembilan Thank you so much!
I am truly thrilled to be able to contribute to Spring Kafka.
I learned a great deal from your thoughtful feedback and guidance throughout this process.
Thank you for your hard work in maintaining such a fantastic open-source project.
I look forward to the opportunity to contribute again in the future.
Thanks again!

@sobychacko

Copy link
Copy Markdown
Contributor

@zooo-code I want to echo what Artem said above. This is a long awaited feature we wanted to support. Thank you for your contribution implementing it. Much appreciated!

@zooo-code

Copy link
Copy Markdown
Contributor Author

@sobychacko Thank you so much for your kind words!
Hearing that this was a long-awaited feature makes me even more thrilled to have worked on it.
I'm really glad I could help out the Spring Kafka community.
It was a great experience, and I'll definitely look for more opportunities to contribute!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DefaultErrorHandler doesn't work with suspend methods

3 participants