Skip to content

DefaultErrorHandler doesn't work with suspend methods #3618

@igloo12

Description

@igloo12

In what version(s) of Spring for Apache Kafka are you seeing this issue?
3.2.4

Describe the bug

Suspend methods don't trigger the default error handler on exception

To Reproduce
I have a bean defined like so

    @Bean
    fun defaultErrorHandler(): DefaultErrorHandler {
        val defaultErrorHandler = DefaultErrorHandler()
        defaultErrorHandler.setBackOffFunction { _, exception ->
            if (exception is HttpRequestTimeoutException) {
                FixedBackOff(2000, FixedBackOff.UNLIMITED_ATTEMPTS)
            } else {
                FixedBackOff(2000, 10)
            }
        }
        return defaultErrorHandler
    }

If I listen like

    @KafkaListener(
        id = "item_updates",
        groupId = "groupid",
        topics = [TOPIC_ITEM_UPDATED],
    )
   suspend fun syncItemListener(message: String) {
                   throw HttpRequestTimeoutException("google.com", 100)
    }

The defaultErrorHandler is not triggered. If I remove the suspend it is triggered

    @KafkaListener(
        id = "item_updates",
        groupId = "groupid",
        topics = [TOPIC_ITEM_UPDATED],
    )
   fun syncItemListener(message: String) {
                   throw HttpRequestTimeoutException("google.com", 100)
    }

Expected behavior

The documentation seems to imply this should work

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions