From 8fe0750993af97cae2e98da300379d1d12f6ce40 Mon Sep 17 00:00:00 2001 From: Shizuo Fujita Date: Thu, 9 Jul 2026 12:46:50 +0900 Subject: [PATCH] output: treat JSON::GeneratorError as unrecoverable error (#5419) **Which issue(s) this PR fixes**: Fixes #5414 **What this PR does / why we need it**: When JSON generation fails for content reasons (e.g. non-UTF-8 bytes, NaN/Infinity), `JSON.generate` raises `JSON::GeneratorError`. This is deterministic for a given chunk, so retrying can never succeed and the chunk should be treated as a bad chunk. **Docs Changes**: N/A **Release Note**: * output: treat JSON::GeneratorError as unrecoverable error Signed-off-by: Shizuo Fujita Signed-off-by: github-actions[bot] --- lib/fluent/plugin/output.rb | 3 ++- test/plugin/test_output_as_buffered_backup.rb | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/output.rb b/lib/fluent/plugin/output.rb index abaa29fa72..ce2a5ffc0b 100644 --- a/lib/fluent/plugin/output.rb +++ b/lib/fluent/plugin/output.rb @@ -28,6 +28,7 @@ require 'fluent/clock' require 'fluent/ext_monitor_require' +require 'json' require 'time' module Fluent @@ -1212,7 +1213,7 @@ def next_flush_time end end - UNRECOVERABLE_ERRORS = [Fluent::UnrecoverableError, TypeError, ArgumentError, NoMethodError, MessagePack::UnpackError, EncodingError] + UNRECOVERABLE_ERRORS = [Fluent::UnrecoverableError, TypeError, ArgumentError, NoMethodError, MessagePack::UnpackError, EncodingError, JSON::GeneratorError] def try_flush chunk = @buffer.dequeue_chunk diff --git a/test/plugin/test_output_as_buffered_backup.rb b/test/plugin/test_output_as_buffered_backup.rb index 73e628c9ad..2956fbf393 100644 --- a/test/plugin/test_output_as_buffered_backup.rb +++ b/test/plugin/test_output_as_buffered_backup.rb @@ -184,7 +184,9 @@ def wait_flush(target_file) 'argument error' => ArgumentError, 'no method error' => NoMethodError, 'msgpack unpack error' => MessagePack::UnpackError, - 'encoding error' => EncodingError) + 'encoding error' => EncodingError, + 'json generate error' => JSON::GeneratorError + ) test 'backup chunk without secondary' do |error_class| Fluent::SystemConfig.overwrite_system_config('root_dir' => TMP_DIR) do id = 'backup_test'