Skip to content

out_kafka2: Skip events with an invalid partition - #577

Merged
kenhys merged 1 commit into
fluent:masterfrom
Watson1978:kafka2-invalid-partition
Sep 1, 2026
Merged

out_kafka2: Skip events with an invalid partition#577
kenhys merged 1 commit into
fluent:masterfrom
Watson1978:kafka2-invalid-partition

Conversation

@Watson1978

Copy link
Copy Markdown
Contributor

producer.produce is called outside the per-event rescue StandardError ... next guard in write, and ruby-kafka coerces the partition with Integer() inside produce, so a record carrying a non numeric partition raises there. The outer handler re-raises and Fluentd retries the same chunk forever: the output stalls, the buffer fills, and events from every source feeding it are dropped. partition comes straight from the record, so one malformed record is enough. This is the ruby-kafka half of #576.

  • Coerce partition with KafkaPluginUtil::PartitionSettings inside the per-event guard, so a bad value skips only that event.
  • Base 10 is explicit, because ruby-kafka reads "010" as octal 8 while default_partition 010 is 10.
  • The -1..2**31 - 1 check also matters here: assign_partitions! only fills in a partition when it is nil, and the encoder packs it with pack("l>"), so 2**40 is silently wrapped to 0 instead of failing.

A partition that is a valid int32 but does not exist on the topic still fails at deliver_messages, which is outside the guard. Telling deterministic delivery failures apart from transient ones is a larger change and is not included.

producer.produce is called outside the per-event rescue, and ruby-kafka
coerces the partition with Integer() inside it, so a record carrying a
non numeric partition raises ArgumentError or TypeError there. The outer
handler re-raises and Fluentd retries the same chunk forever, stalling
every source that feeds this output.

- Coerce partition with KafkaPluginUtil::PartitionSettings inside the
  per-event guard, so a bad value skips only that event
- Base 10 is now explicit: ruby-kafka reads "010" as octal 8, while
  default_partition 010 is 10
- The int32 range check also stops a large partition from being wrapped
  silently by pack("l>") when the request is encoded

Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
@Watson1978
Watson1978 requested a review from kenhys August 31, 2026 06:34
@kenhys
kenhys merged commit a1828a0 into fluent:master Sep 1, 2026
32 checks passed
@Watson1978
Watson1978 deleted the kafka2-invalid-partition branch September 1, 2026 02:44
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