ruby-kafka: Async producer causing main process to exit

I have a question about the design of the async producer.

For context, in our set up, we have our job processing code running in a main process, and most of the jobs result in at least one message that we want to produce to Kafka. From this main process, we call produce on the async producer.

The async producer spawns two threads, the timer thread and the worker thread. The problem we are having is that whenever there is an uncaught exception from the synchronous producer in the worker thread (specifically, we received Kafka::Error, "Correlation id mismatch" from here), the main process crashes. We’ve tracked it down to the async producer setting abort_on_exception to true on the worker thread here in async_producer.rb.

Here is the documentation for abort_on_exception for an instance of a thread:

When set to true, causes all threads (including the main program) to abort if an exception is raised in thr. The process will effectively exit(0).

And here is the documentation for abort_on_exception on the Thread class:

Returns the status of the global abort on exception condition. The default is false. When set to true, will cause all threads to abort (the process will exit(0)) if an exception is raised in any thread. See also Thread.abort_on_exception= .

From the documentation, it seems like there’s no way to avoid ruby-kafka causing the main process toexit(0) if there’s an uncaught exception in the worker thread. Is that true or is there a way to prevent it? Can you explain the design decision behind setting abort_on_exception to true?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (2 by maintainers)

Most upvoted comments

Yup, will work on it tomorrow