Skip to content

defaultCoroutineExceptionHandler probably shouldn't catch kotlin.Error #192

Open
@felixkrull-neuland

Description

@felixkrull-neuland

The default CoroutineExceptionHandler in kotlin-kafka currently catches, logs, and then eats every exception that's thrown in background coroutines. Unfortunately, that includes things like OutOfMemoryError and other fatal errors that probably shouldn't be handled in this way.

Specifically we had an OOMError in the Kafka deserializer which was caught and logged by kotlin-kafka and then not processed further:

KafkaDispatcher with [io.github.nomisRev.kafka.receiver.internals.KafkaSchedulerKt$special$$inlined$CoroutineExceptionHandler$1@61131887, StandaloneCoroutine{Cancelling}@fbd2604, java.util.concurrent.ScheduledThreadPoolExecutor@3ae87e38[Running, pool size = 1, active threads = 1, queued tasks = 2, completed tasks = 62]] failed with an uncaught exception. Report to kotlin-kafka repo please.

The consequence was that a Kafka consumer silently stopped consuming, in a way I didn't initially think to look for. I think the coroutine exception handler should rethrow java.lang.Error/kotlin.Error so that it ends up in the thread uncaught exception handler (at least on JVM as far as I can tell from the docs) which is at least something I as the user of this library can override.

IMO, the ideal solution would be for uncaught exceptions in background tasks to somehow be raised from e.g. a receive() call so they can be handled by the user as normal, but I don't know how feasible that actually is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions