Skip to content

out_rdkafka, out_rdkafka2: Fix crash or hang on shutdown with queued messages - #624

Merged
kenhys merged 1 commit into
fluent:masterfrom
Watson1978:rdkafka2-close-polling-thread
Nov 13, 2026
Merged

kenhys merged 1 commit into
fluent:masterfrom
Watson1978:rdkafka2-close-polling-thread

Conversation

@Watson1978

Copy link
Copy Markdown
Contributor

With rdkafka 0.16.0 or later, rdkafka2 and rdkafka crash the worker with SIGSEGV, or never finish the shutdown, when Fluentd stops while the producer queue still has undelivered messages. The patched NativeKafka#close destroyed the handle after the 10 second wait timed out, but the polling thread was still running.

This PR purges the queue when the wait times out, and waits for the polling thread to stop before destroying the handle. The messages still queued after the wait are dropped, as they were lost on destroy before. The "Queue is forcefully closed after 10 seconds wait" warning is logged as before.

Fixes #611

…messages

With rdkafka 0.16.0 or later, the patched NativeKafka#close destroyed
the handle even when the 10 second wait for the polling thread timed
out. The polling thread leaves its loop only when the queue is empty,
so it was still running when the brokers could not be reached. close
then waited forever for the poll mutex, or the polling thread called
rd_kafka_poll with the destroyed handle and the worker crashed with
SIGSEGV.

When the wait times out, purge the queued and in-flight messages, and
wait for the polling thread to finish before destroying the handle.
close still returns false in this case, so the "Queue is forcefully
closed" warning is logged as before.

Fixes fluent#611

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
@Watson1978

Watson1978 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

The failure in the Ruby 4.0 job with rdkafka >= 0.6.0, < 0.12.0 is not caused by this PR.

  • All 285 tests passed. Then the test process crashed with a segmentation fault on exit.
  • This job uses rdkafka 0.11.1. This PR changes only the patch for rdkafka 0.16.0 or later, and the new test is omitted in this job.
  • The same crash happens on master too, for example ce6d426 with Ruby 4.0 and 80c1e45 with Ruby 3.4.

Flaky tests make CI results hard to trust, so I'll investigate this crash separately.
The crash will be fixed by #633

@kenhys
kenhys merged commit 578238e into fluent:master Nov 13, 2026
44 of 45 checks passed
@Watson1978
Watson1978 deleted the rdkafka2-close-polling-thread branch November 13, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rdkafka2: Worker crashes with SIGSEGV or hangs on shutdown when messages are still queued

2 participants