Skip to content

out_rdkafka2: Skip events with an invalid partition or message_key - #576

Merged
kenhys merged 1 commit into
fluent:masterfrom
Watson1978:rdkafka2-invalid-partition
Aug 31, 2026
Merged

out_rdkafka2: Skip events with an invalid partition or message_key#576
kenhys merged 1 commit into
fluent:masterfrom
Watson1978:rdkafka2-invalid-partition

Conversation

@Watson1978

@Watson1978 Watson1978 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

producer.produce is called from enqueue_with_retry, which sits outside the per-event rescue StandardError ... next guard in write. A record whose partition is not a valid int32 makes the rdkafka FFI binding raise TypeError or RangeError, and neither responds to #code, so both handlers re-raise and Fluentd retries the same chunk forever. One malformed record stalls the output and fills the buffer, dropping events from every source that feeds it.

  • Coerce partition inside the per-event guard so a bad value skips only that event: Integer(value, 10) for strings, and a -1..2**31 - 1 range check. Base 10 is explicit because Integer("010") would otherwise be 8, while default_partition 010 is 10.
  • Coerce message_key with to_s, which librdkafka needs for #bytesize.
  • The partition check lives in KafkaPluginUtil because out_kafka2 needs the same one: ruby-kafka does not validate an explicit partition either, and pack("l>") silently wraps an out of range value. That fix is a separate PR.

@Watson1978
Watson1978 force-pushed the rdkafka2-invalid-partition branch 2 times, most recently from dd79473 to fdb069a Compare August 31, 2026 03:54
@Watson1978
Watson1978 marked this pull request as draft August 31, 2026 04:34
@Watson1978
Watson1978 force-pushed the rdkafka2-invalid-partition branch from fdb069a to 1bfd8e7 Compare August 31, 2026 04:39
@Watson1978
Watson1978 marked this pull request as ready for review August 31, 2026 04:43
@Watson1978
Watson1978 requested a review from kenhys August 31, 2026 04:50
Comment thread lib/fluent/plugin/kafka_plugin_util.rb Outdated
Comment thread test/plugin/test_out_rdkafka2.rb
producer.produce is called outside the per-event rescue, so a record
whose partition is not a valid int32 makes the FFI binding raise
TypeError or RangeError. Neither responds to #code, so
enqueue_with_retry and the outer handler both re-raise it and Fluentd
retries the same chunk forever, stalling every source that feeds this
output.

- Coerce partition inside the per-event guard so a bad value skips only
  that event: Integer(value, 10) for strings, and a -1..2**31 - 1 check
- Coerce message_key with to_s, which librdkafka needs for #bytesize
- Put the partition check in KafkaPluginUtil, since out_kafka2 needs the
  same one: ruby-kafka does not validate an explicit partition either,
  and pack("l>") silently wraps an out of range value

Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
@Watson1978
Watson1978 force-pushed the rdkafka2-invalid-partition branch from 1bfd8e7 to 3eeb8d2 Compare August 31, 2026 05:45
@Watson1978
Watson1978 requested a review from kenhys August 31, 2026 05:50
@kenhys
kenhys merged commit 29f502e into fluent:master Aug 31, 2026
32 checks passed
@Watson1978

Copy link
Copy Markdown
Contributor Author

Thanks

@Watson1978
Watson1978 deleted the rdkafka2-invalid-partition branch August 31, 2026 06:00
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.

2 participants